Java 连接到 RAC 数据库的正确 JDBC URL 是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1646630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:38:28  来源:igfitidea点击:

What is the correct JDBC URL to connect to a RAC database

javajdbc

提问by Vini

We are connecting to Oracle from our code with a simple (custom) JDBC connector class. This class reads the connection properties from a resource file and tries to make a connection to Oracle (thin connection).

我们使用一个简单的(自定义)JDBC 连接器类从我们的代码连接到 Oracle。此类从资源文件中读取连接属性并尝试与 Oracle 建立连接(瘦连接)。

However, recently the database have moved to a RAC and now the application is unable to connect to the DB.

但是,最近数​​据库已移至 RAC,现在应用程序无法连接到数据库。

Here is the TNSPING output:

这是 TNSPING 输出:

Used LDAP adapter to resolve the alias
Attempting to contact (DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db1.myco.com)(PORT=1604))
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db2.myco.com)(PORT=1604)))(CONNECT_DATA=    
SERVICE_NAME=mydb1.myco.com)(SERVER=DEDICATED)))
OK (80 msec)

What would be the correct URL to specify in this case?

在这种情况下指定的正确 URL 是什么?

采纳答案by Pascal Thivent

The URL should look like the following:

URL 应如下所示:

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db1.myco.com)(PORT=1604))
(ADDRESS=(PROTOCOL=TCP)(HOST=tst-db2.myco.com)(PORT=1604)))
(CONNECT_DATA=(SERVICE_NAME=mydb1.myco.com)(SERVER=DEDICATED)))

Actually, just copy the tnsentries from your tnsnames.ora.

实际上,只需从您的tnsnames.ora.

回答by Jason Tholstrup

You may want to look at the OCI drivers. I believe they are supposed to be better performing and handle RAC better.

您可能想查看 OCI 驱动程序。我相信他们应该有更好的表现并更好地处理 RAC。

from http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96590/adg01dev.htm#429762

来自http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96590/adg01dev.htm#429762

OCI provides significant advantages over other methods of accessing an Oracle database:

与其他访问 Oracle 数据库的方法相比,OCI 具有显着优势:

  • More fine-grained control over all aspects of the application design.
  • High degree of control over program execution.
  • Use of familiar 3GL programming techniques and application development tools such as browsers and debuggers.
  • Support of dynamic SQL,method 4.
  • Availability on the broadest range of platforms of all the Oracle programmatic interfaces.
  • Dynamic bind and define using callbacks.
  • Describe functionality to expose layers of server metadata.
  • Asynchronous event notification for registered client applications.
  • Enhanced array data manipulation language (DML) capability for array INSERTs, UPDATEs, and DELETEs.
  • Ability to associate a commit request with an execute to reduce round-trips.
  • Optimization for queries using transparent prefetch buffers to reduce round-trips.
  • Thread safety so you do not have to use mutual exclusive locks (mutex) on OCI handles.
  • The server connection in nonblocking mode means that control returns to the OCI code when a call is still executing or could not complete.
  • 对应用程序设计的所有方面进行更细粒度的控制。
  • 对程序执行的高度控制。
  • 使用熟悉的 3GL 编程技术和应用程序开发工具,例如浏览器和调试器。
  • 支持动态SQL,方法4。
  • 在所有 Oracle 编程接口的最广泛平台上的可用性。
  • 使用回调动态绑定和定义。
  • 描述公开服务器元数据层的功能。
  • 已注册客户端应用程序的异步事件通知。
  • 用于数组插入、更新和删除的增强的数组数据操作语言 (DML) 功能。
  • 能够将提交请求与执行相关联以减少往返。
  • 使用透明预取缓冲区优化查询以减少往返。
  • 线程安全,因此您不必在 OCI 句柄上使用互斥锁 (mutex)。
  • 非阻塞模式下的服务器连接意味着当调用仍在执行或无法完成时,控制返回到 OCI 代码。

回答by SquishFish

The point of a tnsnames file, the older Oracle Names server, and the newer, recommended LDAP directory server method of resolving database names is to avoid having to hardcode hostnames, addresses, ports, etc. into your connection string. The DBAs should be able to move the database to a new host or port without breaking anything.

tnsnames 文件、较旧的 Oracle Names 服务器和较新的、推荐的 LDAP 目录服务器解析数据库名称方法的要点是避免将主机名、地址、端口等硬编码到您的连接字符串中。DBA 应该能够在不破坏任何内容的情况下将数据库移动到新的主机或端口。

The best way to set your thin connect URL is with the following syntax:

设置瘦连接 URL 的最佳方法是使用以下语法:

jdbc:oracle:thin:@ldap://<OID server name>:<OID port>/<DB SID or Service Name>,cn=OracleContext,dc=<yourdomain>

jdbc:oracle:thin:@ldap://<OID server name>:<OID port>/<DB SID or Service Name>,cn=OracleContext,dc=<yourdomain>

So in your case, if "oid" were the DNS-resolvable name of the OID server at your company, and it used port 5000, it would be:

因此,在您的情况下,如果“oid”是您公司 OID 服务器的 DNS 可解析名称,并且它使用端口 5000,则它将是:

jdbc:oracle:thin:@ldap://oid:5000/mydb1,cn=OracleContext,dc=myco,dc=com

jdbc:oracle:thin:@ldap://oid:5000/mydb1,cn=OracleContext,dc=myco,dc=com

If your DBAs have not yet set up OID, they are woefully behind. Time to get new DBAs.

如果您的 DBA 还没有设置 OID,那么他们就落后了。是时候获得新的 DBA 了。

-squish

-挤压

回答by Vahid Nowrouzi

also you can use scan ip in oracle 11g r2 instead of your nodes ip:

您也可以在 oracle 11g r2 中使用 scan ip 而不是您的节点 ip:

  testi=(DESCRIPTION = 
(ADDRESS_LIST= 
 (ADDRESS= (PROTOCOL = TCP)(HOST = scan-ip-or-name)(PORT = 1521))
 (FAILOVER = on)
 (LOAD_BALANCE = on)
)   
(CONNECT_DATA=
 (SERVICE_NAME = testi)
) )

回答by Francisco Javier Ocampo

I'm not sure if you solve your problem, but I faced the same problem and this solution works for me:

我不确定你是否解决了你的问题,但我遇到了同样的问题,这个解决方案对我有用:

jdbc:oracle:oci:@(DESCRIPTION=(FAILOVER=on)(ADDRESS=(PROTOCOL=TCP)(HOST=**mi.host**)(PORT=**1521**))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=**serviceName**)))

回答by arn-arn

this is what i used:

这是我使用的:

jdbc:oracle:thin:@ldap://xxx:389/yyy,cn=OracleContext,dc=zzz,dc=com 
ldap://xxx:389/yyy,cn=OracleContext,dc=zzz,dc=com 
ldap://xxx:389/yyy,cn=OracleContext,dc=zzz,dc=com