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

查看:27
本文介绍了如何使用服务名称而不是 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.现在我需要连接到一个不同的 Oracle 数据库,它不使用 SID,而是使用 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.

我试过了,但没有用:

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

精简式服务名称语法

瘦风格的服务名称仅受 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

此外,根据 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)))

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

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