使用 OCI 驱动程序的 Oracle OID 的 JDBC 连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8386833/
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
JDBC Connect String for Oracle OID Using OCI Driver
提问by Josh Harness
I know how to connect to oracle using OID and the thin client jdbc driver:
我知道如何使用 OID 和瘦客户端 jdbc 驱动程序连接到 oracle:
jdbc:oracle:thin:@ldap://server:port/xyz,cn=abc,dc=def,dc=ghi
I cannot, though, connect using jdbc, oci and oid. Oracle keeps outputing an invalid URL message. I've tried the following:
但是,我无法使用 jdbc、oci 和 oid 进行连接。Oracle 不断输出无效的 URL 消息。我尝试了以下方法:
jdbc:oracle:oci10:@ldap://server:port/xyz,cn=abc,dc=def,dc=ghi
jdbc:oracle:oci10:@xyz
I've got my ORACLE_HOME set for a 10g database. I've added the libraries to LD_LIBRARY_PATH. I've set java.library.path system property. Finally, I can connect using sqlplus and the symbolic oid name.
我已经为 10g 数据库设置了 ORACLE_HOME。我已将库添加到 LD_LIBRARY_PATH。我已经设置了 java.library.path 系统属性。最后,我可以使用 sqlplus 和符号 oid 名称进行连接。
What connect string should be used?
应该使用什么连接字符串?
回答by Jay
This URL works for me,
这个网址对我有用,
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:oci:@<name_from_tnsnames.ora>", "user", "password");
If you are using OCI driver, you need a Oracle client installation from where you run this code. And you should have the valid working entry in the tnsnames.ora.
如果您使用 OCI 驱动程序,则需要从运行此代码的位置安装 Oracle 客户端。并且您应该在 tnsnames.ora 中有有效的工作条目。
If you use incompatible ojdbc jar you would get java.library.path error. I used the ojdbc6.jar from the oracle client installation location C:\app\client\jjayarman\product\12.1.0\client_1\jdbc\lib\ojdbc6.jar
.
如果使用不兼容的 ojdbc jar,则会出现 java.library.path 错误。我使用了 oracle 客户端安装位置的 ojdbc6.jar C:\app\client\jjayarman\product\12.1.0\client_1\jdbc\lib\ojdbc6.jar
。
I use Oracle Database 12c / Java 1.7 on 64bit Windows7
我在 64 位 Windows7 上使用 Oracle Database 12c / Java 1.7
回答by Mark Rotteveel
As far as I know using the protocol :oci10:
is incorrect, it should be :oci:
. See also this FAQ on Oracle JDBC
据我所知,使用协议:oci10:
是不正确的,应该是:oci:
. 另请参阅有关 Oracle JDBC 的常见问题解答