我们正在为我们的连接配置使用 OID/LDAP 查找。TNS_ADMIN
环境变量和Java 属性都oracle.net.tns_admin
设置正确,并指向包含 sqlnet.ora 和 ldap.ora 的目录。但是,JDBC 连接 URL: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)
以下类型的连接字符串连接成功:
- 完整的 TNS 字符串:
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host.company.com)(PORT=####))(CONNECT_DATA=(SERVICE_NAME=service_name)))
- 完整的 LDAP 网址:
jdbc:oracle:thin:@ldap://oid.company.net:####/ourtnsname,CN=OracleContext,dc=company,dc=net
这似乎暗示问题出在 LDAP/OID 查找上。但是,运行tnsping ourtnsname
也连接成功。
在进行 OID/LDAP 查找时,有没有办法在连接字符串中只使用 TNS 别名?
为了完整起见,这里是相关的 Java:
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);