我们正在使用 OID/ LDAP 搜索我们的连接配置。 设置正确, 包括 < code> TNS_ ADMIN < /code > 环境变量和 < code> oracle. net. tns_ admin < /code > Java 属性, 并指向包含 sqlnet. ora 和 ldap. ora 的目录。 但是, JDBC 连接 URL: < code> jdbc:oracle: Thin: @ourtnsalias 在试图连接时会丢出例外 :
java.sql.SQLRecoverableException: IO Error: could not resolve the connect identifier "ourtnsalias"
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:458)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TnsTest.main(TnsTest.java:29)
Caused by: oracle.net.ns.NetException: could not resolve the connect identifier "tnsalias"
at oracle.net.resolver.NameResolver.resolveName(NameResolver.java:181)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:416)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:687)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:247)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)
... 7 more
Exception in thread "main" java.lang.NullPointerException
at TnsTest.main(TnsTest.java:46)
成功连接到以下连接字符串的口味 :
- Full TNS string:
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host.company.com)(PORT=####))(CONNECT_DATA=(SERVICE_NAME=service_name)))
- Full LDAP url:
jdbc:oracle:thin:@ldap://oid.company.net:####/ourtnsname,CN=OracleContext,dc=company,dc=net
这似乎意味着问题在于 LDAP/OID 查询。 然而,运行 < code> tnsping ourtnsname 也会成功连接 。
在进行 OID/ LDAP 搜索时, 是否有办法在连接字符串中只使用 TNS 别名?
为了完整起见,这里是相关的爪哇:
String connectionURL = "jdbc:oracle:thin:@ourtnsalias";
System.setProperty("oracle.net.tns_admin", "c:/oracle/network/admin");
Class.forName("oracle.jdbc.OracleDriver");
Connection c = DriverManager.getConnection(connectionURL, userid, password);