Links

  • 1. Sogeti
  • 2. JBoss
  • 3. IBM
  • 4. Oracle
  • 5. SpringSource
  • 6. NL-JUG
  • 7. Java

Archives

Syndication  RSS 2.0

RSS 1.0
RSS 2.0

Bookmark this site

Add 'JCN Blog' site to delicious  Add 'JCN Blog' site to technorati  Add 'JCN Blog' site to digg  Add 'JCN Blog' site to dzone

Posted by Barend Garvelink at 12:25 on Sunday 3 February    Add 'Oracle thin JDBC to TNS name' site to delicious  Add 'Oracle thin JDBC to TNS name' site to technorati  Add 'Oracle thin JDBC to TNS name' site to digg  Add 'Oracle thin JDBC to TNS name' site to dzone

To establish an Oracle thin JDBC connection to a TNS alias (tnsname), make sure you pass the oracle.net.tns_admin system property to the JVM. Its value should be the directory in which your tnsnames.ora file is located. After that, you can just pass the TNS alias in place of the host name in the JDBC URL.

E.g. if you simply try to connect to jdbc:oracle:thin:@MYDB, which is in your tnsnames.ora file, you’ll get an SQLException with a detail message of Io exception: Unknown host specified. If you fire up the JVM with a -Doracle.net.tns_admin=/oracle/10g/NETWORK/ADMIN, or use System.setProperty(String,String) after startup, the connection will be established successfully.

Oh yeah? Well what’s this SQLException “Io exception: SO Exception was generated“, then? you ask? The exception message is a bit deceptive, as the “SO” suggests OCI when we’re really using thin. I encountered this exception with the ojdbc14.jar included with OC4J standalone 10.1.3.1.0. Using the JDBC driver from the Oracle client 10.2 package stops it occuring, but causes OC4J standalone to log a warning about a missing getStatistics method every few seconds, which is hardly any less annoying. I’m not sure what’s causing it to happen, but a version upgrade seems to fix it. If that’s not an option, you can always use good old jdbc:oracle:thin:@host:port/service, which is what I settled for in the end.


© 2014 Java Competence Network. All Rights Reserved.