我怎样才能连接到从蚂蚁使用TNSNAME Oracle数据库? [英] How can I connect to an Oracle database from Ant using the tnsname?

查看:286
本文介绍了我怎样才能连接到从蚂蚁使用TNSNAME Oracle数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找类似蚂蚁SQL任务的东西,但将接受格式的JDBC网址:

I am looking for something similar to the Ant sql task but that will accept a JDBC url of the format:

JDBC:神谕:薄:@TNS_NAME

jdbc:oracle:thin:@TNS_NAME

一种可能的办法似乎是写一个使用OracleDataSource来创建连接我自己的Ant任务,但有没有办法做到这一点直蚂蚁?

One possible approach seems to be to write my own Ant task that uses an OracleDataSource to create the Connection, but is there a way to do this straight in Ant?

编辑:
感谢您的答复迄今家伙。我希望它能帮助,如果我阐述多一点上,我发现了错误。

Thanks for the responses so far guys. I hope it helps if I elaborate a bit more on the error I'm getting.

我的Ant任务如下所示:

My Ant task looks as follows:

<target name="MyTarget" >
    <property name="oracle.net.tns_admin" value="/opt/oracle/product/10.2.0.1/NETWORK/ADMIN" />
    <property name="jdbc.driver" value="ojdbc5.jar" />
    <property name="jdbc.i18n.support" value="orai18n.jar" />
    <property name="jdbc.driver.class" value="oracle.jdbc.OracleDriver" />
    <path id="sql.class.path">
        <pathelement location="${jdbc.driver}" />
        <pathelement location="${jdbc.i18n.support}" />
    </path>

    <sql driver="${jdbc.driver.class}" url="jdbc:oracle:thin:@THE_TNS_NAME" userid="USER" password="PASSWORD" classpathref="sql.class.path" >
        <![CDATA[
        #SOME ARBITRARY SQL HERE
        ]]>
    </sql>
</target>

这失败,出现错误:

值java.sql.SQLException:IO异常:指定未知主机

java.sql.SQLException: Io exception: Unknown host specified

与更换网址的jdbc:神谕:薄:@HOST:端口:实例。做工精细,而且我也可以用tnsping上面使用的TNS名称,所以我知道它是有效的。

Replacing the url with "jdbc:oracle:thin:@HOST:PORT:INSTANCE" works fine, and I can also tnsping the tns name used above, so I know it's valid.

推荐答案

只是这个今天工作,偶然发现了缺少的部分。 TNS的位置需要设置为系统属性,如下所示:的 Oracle瘦JDBC来TNS名称

Was just working with this today and stumbled upon the missing piece. The TNS location needs to be set as a system property as indicated here: Oracle thin JDBC to TNS name

要建立一个Oracle瘦JDBC连接TNS别名(TNSNAME)
  确保你的oracle.net.tns_admin系统属性传递给JVM。
  它的值应该是在你的tnsnames.ora文件所在的目录
  位于。在此之后,你可以通过TNS别名地方
  在JDBC URL的主机名。

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.

例如。如果你只是试图连接到JDBC:神谕:薄:@MYDB,这
  在你的tnsnames.ora文件,你会得到一个SQLException带详细
  IO异常的消息:指定未知主机。如果你火起来的JVM
  用-Doracle.net.tns_admin = / ORACLE / 10G / NETWORK / ADMIN,或使用
  System.setProperty(字符串,字符串)启动后,连接
  将成功建立。

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.

这样做我能单独使用TNS别名连接成功后

After doing this I was able to successfully connect using the TNS alias alone.

这篇关于我怎样才能连接到从蚂蚁使用TNSNAME Oracle数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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