如果使用 Oracle 钱包,正确的 JDBC URL 语法是什么?

2021-12-21 00:00:00 oracle jdbc

有两种 URL 语法,旧语法仅适用于 SID,新语法适用于 Oracle 服务名称.
旧语法

There are 2 URL syntax, old syntax which will only work with SID and the new one with Oracle service name.
Old syntax

jdbc:oracle:thin:@[HOST][:PORT]:SID

新语法

jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE

什么是正确的 JDBC URL 语法如果使用 Oracle 钱包?
根据这篇文章,应使用以下 URL 语法:

What is correct JDBC URL syntax if Oracle wallets are used?
According to this article following URL syntax should be used:

jdbc:oracle:thin:/@db_alias  

但正如我所见,以下网址也有效:

But as I can see following URL works too:

jdbc:oracle:thin:@db_alias

这些语法中哪些是正确的?

Which of these syntaxes are correct?

推荐答案

当您使用带有 JDBC 字符串的 Oracle Wallet 时,这两种语法都是允许的,只要您的db_alias"设置在显然是您的电子钱包商店.

When you are using Oracle Wallet with a JDBC string, both syntax's are allowed, so long as your "db_alias" is setup in your Wallet store obviously.

现在,就将 SQL*Plus 与 Oracle Wallet 一起使用而言,Oracle Wallet 允许的唯一格式是:

Now, as far as using SQL*Plus with Oracle Wallet, the only format allowed with Oracle Wallet is:

/@db_alias

顺便说一下,您引用的那篇文章(以及其他) 指定如果您使用 OCI 驱动程序,则只能使用 JDBC 进行连接,而不能使用瘦客户端.这通常是因为 Java 不了解 Oracle TNS 和 SQLNET 文件.这实际上不是真的.您可以使用 JDBC 瘦驱动程序与最新的 Oracle 客户端进行连接.JDBC 驱动程序,但它只需要一些设置.请参阅 http://tech.shopzilla.com/2011/09/oracle-wallet-with-thin-driver-with-connection-pool-with-database-timeouts/ 了解相关信息,以下是简短摘要.

By the way, that article you referenced (and others) specifies you can only connect using JDBC if you use the OCI drivers, and not the thin client. This is/was typically because Java had no knowledge of the Oracle TNS and SQLNET files. This is in fact not true; you can connect using the JDBC thin driver with the latest Oracle Client & JDBC Drivers, but it just requires some setup. See http://tech.shopzilla.com/2011/09/oracle-wallet-with-thin-driver-with-connection-pool-with-database-timeouts/ for info on that, and below for a short summary.

将 Oracle Wallet 与 JDBC 瘦驱动程序一起使用

  1. 像往常一样配置 Oracle Wallet (Oracle 数据库随附客户端),在您的 tnsnames.ora 和 sqlnet.ora 文件中创建适当的条目以及钱包中的凭证条目
  2. 将以下 JAR 添加到您的 Java 类路径中.您应该从 Oracle 11g 客户端获取这些,它们可以在客户端安装所在的jdbc"和/或jlib"目录中找到
    • Oracle JDBC 驱动程序 - ojdbc6.jar
    • Oracle 钱包 - oraclepki.jar
    • Oracle 安全证书 - osdt_cert.jar
    • Oracle 安全核心 - osdt_core.jar
  1. Configure Oracle Wallet as usual (which comes with the Oracle Database Client), creating the appropriate entries in your tnsnames.ora and sqlnet.ora files as well as the credential entry in your wallet
  2. Add the following JARs to your Java classpath. You should get these from the Oracle 11g client, and they can be found in the "jdbc" and/or "jlib" directories of where the client install is
    • Oracle JDBC Driver - ojdbc6.jar
    • Oracle Wallet - oraclepki.jar
    • Oracle Security Certs - osdt_cert.jar
    • Oracle Security Core - osdt_core.jar
  • -Doracle.net.tns_admin=C:myTNSdir
  • -Doracle.net.wallet_location=C:mywalletdir

相关文章