(转)Oracle thin JDBC to TNS name

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值