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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7634196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:36:30  来源:igfitidea点击:

What is correct JDBC URL syntax if Oracle wallets are used?

oraclejdbc

提问by Volodymyr Bezuglyy

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

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

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

New syntax

新语法

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

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

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

jdbc:oracle:thin:/@db_alias  

But as I can see following URL works too:

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

jdbc:oracle:thin:@db_alias

Which of these syntaxes are correct?

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

回答by David Hergert

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.

当您使用带有 JDBC 字符串的 Oracle Wallet 时,这两种语法都是允许的,只要您的“db_alias”显然是在您的 Wallet 商店中设置的。

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

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

/@db_alias

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 canconnect 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.

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

Using Oracle Wallet with JDBC Thin Driver

将 Oracle Wallet 与 JDBC 瘦驱动程序结合使用

  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
  3. Start your Java application with the following system properties, pointing at your respective TNS and wallet directories:
    • -Doracle.net.tns_admin=C:\myTNSdir
    • -Doracle.net.wallet_location=C:\mywalletdir
  4. Then you can use a thin JDBC connection string in your application like so: jdbc:oracle:thin:/@MY_WALLET_DB_ENTRY
  1. 像往常一样配置 Oracle Wallet (随 Oracle Database Client 一起提供),在您的 tnsnames.ora 和 sqlnet.ora 文件中创建适当的条目以及您的钱包中的凭证条目
  2. 将以下 JAR 添加到您的 Java 类路径。您应该从 Oracle 11g 客户端获取这些,它们可以在客户端安装位置的“jdbc”和/或“jlib”目录中找到
    • Oracle JDBC 驱动程序 - ojdbc6.jar
    • 甲骨文钱包 - oraclepki.jar
    • Oracle 安全证书 - osdt_cert.jar
    • Oracle 安全核心 - osdt_core.jar
  3. 使用以下系统属性启动您的 Java 应用程序,指向您各自的 TNS 和 wallet 目录:
    • -Doracle.net.tns_admin=C:\myTNSdir
    • -Doracle.net.wallet_location=C:\mywalletdir
  4. 然后,您可以在应用程序中使用瘦 JDBC 连接字符串,如下所示: jdbc:oracle:thin:/@MY_WALLET_DB_ENTRY