English 中文(简体)
通过 LDAP/OID 查找 Thin JDBC 客户端解决 Oracle SID 问题
原标题:Problems resolving Oracle SID via LDAP/OID lookup with Thin JDBC Client

我们正在使用 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);
问题回答

在用这个击打我的头撞墙之后,我们发现问题在于 TNS 名称条目有无效的标签/跨多行的间隔,导致它无法正确分析。

在我们的案例中,TNSPING能够正确解析 TNSNAMES. Ora 文件, 但jdbc Oracle司机却不是。

删去 TNSNAMEs 条目中的所有间距, 然后小心地将其重新添加, 注意这里描述的规则 :

http://docs.oracle.com/cd/A57673_01/DOC/net/doc/NWUS233/apb.htm

帮助我们解决问题。

导致我们找到答案的是,在更改连接标识符时,我们会发现一个不同的错误,即从此切换:

jdbc:oracle:thin:@ourtnsalias

致:

jdbc:oracle:thin:@unknown

给出了一个不同的错误( 在 SysInterporations 进程监视器中检查, 以确保 TNSNAMES. ora 文件实际上正在读取), 这表明它正在解析 TNS 文件, 但是在条目中有些错误, 正在让事情发生翻转 。

如果 JDBC Oracle 客户端返回一个更有意义的错误, 即“ 无法解析 TNS 条目连接标识符 ”!

希望这能帮助别人出:)

我不是一个程序设计员,而是一个Dba,曾帮助过一位同事处理同一问题。

System.setProperty("或acle.net.tns_admin", "c:/或acle/netw或k/admin"); 

应该是

System.setProperty("或acle.net.tns_admin", "c://或acle//netw或k//admin"); 

System.setProperty("或acle.net.tns_admin", "c:\或acle\netw或k\admin");

在您的 tnsnames. ora 中查找无效字符 。

我曾经

test, test.WORLD=...

在我的档案中。 更改为

test.WORLD=

这个问题已经解决。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

How to make a one to one left outer join?

I was wondering, is there a way to make a kind of one to one left outer join: I need a join that matches say table A with table B, for each record on table A it must search for its pair on table B, ...

Insert if not exists Oracle

I need to be able to run an Oracle query which goes to insert a number of rows, but it also checks to see if a primary key exists and if it does, then it skips that insert. Something like: INSERT ALL ...

How can I store NULLs in NOT NULL field?

I just came across NULL values in NOT-NULL fields in our test database. How could they get there? I know that NOT-NULL constraints can be altered with NOVALIDATE clause, but that would change table s ...

Type reference scope

I m studying databases and am currently working on a object-relational DB project and I ve encountered a small problem with the number of possible constraints in an object table. I m using "Database ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

热门标签