Java JDBC - 如何使用 tnsnames.ora 连接到 Oracle [英] Java JDBC - How to connect to Oracle using tnsnames.ora

查看:60
本文介绍了Java JDBC - 如何使用 tnsnames.ora 连接到 Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tnsnames.ora 文件包含 Databases 及其描述(host + port).>

  • 是否可以依靠上面提到的文件建立连接?(比如只提供数据库名称):

  • 为了找到这个文件,我必须知道默认的 oracle home 我需要在 Windows 注册表中检查 HKEY_LOCAL_MACHINESoftwareOracle 然后拥有所有的 KEY_XXX 文件,然后检查 %PATH% 上哪个先出现.有没有办法在客户端电脑上自动找到这个文件?

解决方案

我什至不知道可以在瘦驱动程序中使用 tnsnames,但显然它是在版本 10 中添加的:

http://docs.oracle.com/cd/B19306_01/java.102/b14355/urls.htm#BEIDIJCE

特别是:

<块引用>

注意:

将 TNSNames 与 JDBC Thin 驱动程序一起使用时,您必须将 oracle.net.tns_admin 属性设置为包含 tnsnames.ora 文件的目录.

java -Doracle.net.tns_admin=%ORACLE_HOME% etworkadmin

如前所述,我还没有检查这实际上是否有效.

我不认为通过某些 Oracle 功能可以使用查找实际网络配置目录"逻辑.您必须按照问题中的概述手动执行此操作,或者可能依赖于存在的 TNS_ADMIN 环境变量.在这种情况下,java 调用将是

java -Doracle.net.tns_admin=%TNS_ADMIN%

tnsnames.ora file contains the Databases and the their description (host + port).

  • Is it possible to establish a connection relying on the file mentioned above? (Say by providing only the DB name):

  • In order to find this file, I have to know the default oracle home I need to check in the windows registry for HKEY_LOCAL_MACHINESoftwareOracle and then to have all the KEY_XXX files and then check which one appears first on the %PATH%. Is there a way to automatically find this file on the client computer?

解决方案

I wasn't even aware that using tnsnames with the thin driver is possible, but apparently it was added somewhere in version 10:

http://docs.oracle.com/cd/B19306_01/java.102/b14355/urls.htm#BEIDIJCE

In particular:

Note:

When using TNSNames with the JDBC Thin driver, you must set the oracle.net.tns_admin property to the directory that contains your tnsnames.ora file.

java -Doracle.net.tns_admin=%ORACLE_HOME% etworkadmin

As mentioned, I haven't checked if this actually works.

I don't think that the "find the actual network config directory" logic is available via some Oracle function. You'll have to do it manually as outlined in your question, or maybe rely on the TNS_ADMIN environment variable being present. In that case, the java invocation would be

java -Doracle.net.tns_admin=%TNS_ADMIN%

这篇关于Java JDBC - 如何使用 tnsnames.ora 连接到 Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆