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

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

问题描述

tnsnames.ora 文件包含数据库及其描述( host + port )。

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):

为了找到这个文件,我必须知道我需要在windows中检查的默认oracle主页 HKEY_LOCAL_MACHINE \Software\Oracle 的注册表,然后获取所有 KEY_XXX 文件,然后检查哪一个出现在%PATH%上。有没有办法在客户端计算机上自动查找此文件?

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_MACHINE\Software\Oracle 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?

推荐答案

我甚至不知道使用带有瘦驱动程序的tnsnames是可能的,但显然它是在版本10中的某处添加的:

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

特别是:

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%\network\admin

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

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

我不认为找到实际的网络配置目录逻辑可通过某些Oracle函数获得。您必须按照问题中的说明手动执行此操作,或者可能依赖于存在的TNS_ADMIN环境变量。在这种情况下,java调用将是

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天全站免登陆