Java JDBC - 如何使用服务名称而不是SID连接到Oracle [英] Java JDBC - How to connect to Oracle using Service Name instead of SID

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

问题描述

我有一个使用JDBC(通过JPA)的Java应用程序,它使用主机名,端口和Oracle SID连接到开发数据库,​​如下所示:

I have a Java application that uses JDBC (via JPA) that was connecting to a development database using hostname, port and Oracle SID, like this:

jdbc:oracle:thin:@ oracle.hostserver1.mydomain.ca:1521:XYZ

XYZ是Oracle SID。现在我需要连接到不使用SID的不同Oracle数据库,而是使用Oracle服务名称。

XYZ was the Oracle SID. Now I need to connect to a different Oracle database that does not use a SID, but uses an Oracle "Service Name" instead.

我试过这个,但它没有工作:

I tried this but it doesn't work:

jdbc:oracle:thin:@ oracle.hostserver2.mydomain.ca:1522:ABCD

ABCD是另一个数据库的服务名称。

ABCD is the Service Name of the other database.

我做错了什么?

推荐答案

http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/urls.htm#BEIDHCBA


精简式服务名称语法

Thin-style Service Name Syntax

仅支持精简式服务名称JDBC瘦驱动程序。语法为:

Thin-style service names are supported only by the JDBC Thin driver. The syntax is:

@ // host_name:port_number / service_name

@//host_name:port_number/service_name

例如:

jdbc:oracle:thin:scott / tiger @ // myhost:1521 / myservicename

jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename

所以我会尝试:

jdbc:oracle:thin:@ // oracle.hostserver2.mydomain.ca:1522/ABCD

jdbc:oracle:thin:@//oracle.hostserver2.mydomain.ca:1522/ABCD

另外,根据Robert Greathouse的回答,您还可以在JDBC URL中指定TNS名称,如下所示:

Also, per Robert Greathouse's answer, you can also specify the TNS name in the JDBC URL as below:

jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=blah.example.com)(PORT=1521)))(CONNECT_DATA=(SID=BLAHSID)(GLOBAL_NAME=BLAHSID.WORLD)(SERVER=DEDICATED)))

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

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