ITPub博客

首页 > Linux操作系统 > Linux操作系统 > JDBC连接Oracle RAC的连接串配置

JDBC连接Oracle RAC的连接串配置

原创 Linux操作系统 作者:hunterdiary 时间:2009-04-16 21:42:17 0 删除 编辑
JDBC连接Oracle RAC的连接串配置
2009-02-25 10:43

http://www.eygle.com/digest/2008/06/jdbcoracle_rac.html

这里虽然引用了eygle的文章,但我要说这样的写法是不准确的。JDBC Thin 到目前为止,仍是不支持TAF的,而且将来也应该不会支持。Oracle的推荐做法是FCF。但这样写也没有任何影响,至少到目前为止,尚未发现。它使得 中断的连接在重连时可以获得正确的连接。这样来讲,可能一般的应用真的不需要TAF。

Feature Differences Between JDBC OCI and JDBC Thin Drivers

JDBC OCI Driver JDBC Thin Driver

OCI connection pooling

Default support for Native XA

Transparent Application Failover (TAF)

OCI Client Result Cache


Feature List
Feature Server-Side Internal JDBC OCI JDBC Thin

Native XA

9.0.1

10.1.0


TAF

NA

9.0.1

NA


Fast Connection Failover

10.1.0.3

10.1.0.3


Service Names in URLs

9.2.0

10.2.0



详细信息请参看 B28359_01/java.111/b31224/overvw.htm#BABJFBIF

这个连接串通常写在中间件里,是否 Native XA 和 连接时的 Failover 已经足够了呢?那么 FCF 更广泛的意义是什么呢?据说,在BEA被收购前,只有Oracle自家的App Server 支持 FCF,不知道现在的情形是什么样子。

jdbc连接oracle的连接串如下:

String url="jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = host2)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = host1)(PORT = 1521))(LOAD_BALANCE = yes)(FAILOVER = ON)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = db.domain)(FAILOVER_MODE=(TYPE = SELECT)(METHOD = BASIC)(RETIRES = 20)(DELAY = 15))))";

红色部分为可以删掉的部分,因为那是OCI的写法。

java测试程序如下:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test {

public static void main(String arg[]) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = host1)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = host2)(PORT = 1521))(LOAD_BALANCE = yes)(FAILOVER = ON)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = db.domain)(FAILOVER_MODE=(TYPE = SELECT)(METHOD = BASIC)(RETIRES = 20)(DELAY = 15))))";
Connection c = DriverManager.getConnection(url,"aa","aa");
Statement s = c.createStatement();
ResultSet r = s.executeQuery("select 1 from dual");
while(r.next()) {
System.out.println(r.getString(1));
}
}catch(Exception e) {
System.out.println(e.toString());
}
}

}

附加 查看会话的故障切换信息的 SQL 查询

COLUMN instance_name    FORMAT a13
COLUMN host_name        FORMAT a9
COLUMN failover_method  FORMAT a15
COLUMN failed_over      FORMAT a11

SELECT
    instance_name
  , host_name
  , NULL AS failover_type
  , NULL AS failover_method
  , NULL AS failed_over
FROM v$instance
UNION
SELECT
    NULL
  , NULL
  , failover_type
  , failover_method
  , failed_over
FROM v$session
WHERE username = 'SYSTEM';
INSTANCE_NAME HOST_NAME FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER
------------- --------- ------------- --------------- -----------
orcl1         linux1
                        SELECT        BASIC           NO
详细请参看 
http://www.oracle.com/technology/global/cn/pub/articles/hunter_rac10gr2_iscsi_3.html
新增Oracle官方FCF Demo:
http://www.oracle.com/technology/products/ias/hi_av/fcf_viewlet_swf.html

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8591234/viewspace-590698/,如需转载,请注明出处,否则将追究法律责任。

下一篇: ORACLE DATA GUARD
请登录后发表评论 登录
全部评论

注册时间:2009-04-03

  • 博文量
    8
  • 访问量
    22373