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


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 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, 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 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.

© 2017 Java Competence Network. All Rights Reserved.