title: Problems resolving Oracle SID via LDAP/OID lookup with Thin JDBC Client
body: <p>We are using OID/LDAP lookup for our connection configuration. Both the <code>TNS_ADMIN</code> environment variable and the <code>oracle.net.tns_admin</code> Java property are set correctly and points to a directory that contains sqlnet.ora and ldap.ora.  However, the JDBC connection URL: <code>jdbc:oracle:thin:@ourtnsalias</code> throws exception when attempting to connect:</p>
  
  <pre><code>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.&lt;init&gt;(PhysicalConnection.java:546)
          at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(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)
  </code></pre>
  
  <p>The following flavors of the connection string connect successfully:</p>
  
  <ul>
  <li>Full TNS string:<br/>
  <code>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host.company.com)(PORT=####))(CONNECT_DATA=(SERVICE_NAME=service_name)))</code></li>
  <li>Full LDAP url:<br/>
  <code>jdbc:oracle:thin:@ldap://oid.company.net:####/ourtnsname,CN=OracleContext,dc=company,dc=net</code></li>
  </ul>
  
  <p>This would seem to imply that the problem is with the LDAP/OID lookup. However, running <code>tnsping ourtnsname</code> also connects successfully.</p>
  
  <p>Is there any way to use only a TNS Alias in the connection string when doing OID/LDAP lookup?</p>
  
  <p>For completeness sake, here is the relevant Java:</p>
  
  <pre><code>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);
  </code></pre>