码迷,mamicode.com
首页 > 数据库 > 详细

java oracle thin 和 oci 连接方式实现多数据库的故障切换

时间:2014-08-14 20:38:49      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:java   oracle thin oci   oracle thin   oracle oci   数据库故障切换   

java oracle thin 和 oci 连接方式实现多数据库的故障切换

一、thin方式
其中URL为
jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)
      (ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))
      (ADDRESS=(PROTOCOL=TCP)(HOST=10.132.111.14)(PORT=1521))
      (CONNECT_DATA=(SERVICE_NAME=bomc)))

其中LOAD_BALANCE=on表示负载开启,java以随机的方式创建会话连接;
LOAD_BANLANCE=off表示负载关闭,java以顺序的方式创建会话连接,只有
当第一个数据库出现故障无法连接时才会选择第二个数据库进行会话连接。


二、oci方式
1. 具体程序部署的本机需要安装oracle客户端,并在PATH路径下指定oracle客户端bin目录,并拷贝
oracle客户端里自带的jdbc驱动到自己的工程项目。

2. 配置TNSNAMES.ORA文件如下:
HA_DB =
  (DESCRIPTION_LIST =
     (LOAD_BALANCE = on)
     (FAILOVER = on)    
       (DESCRIPTION =
           (ADDRESS_LIST =
              (LOAD_BALANCE=OFF)
              (FAILOVER=ON)
              (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
           )
           (CONNECT_DATA =
              (SERVICE_NAME = bomc)
              (INSTANCE_NAME = bomc)
              (FAILOVER_MODE=(TYPE=session)(METHOD=basic)(RETRIES=4)(DELAY=1))
           )
        )
        (DESCRIPTION =
           (ADDRESS_LIST =
              (LOAD_BALANCE=OFF)
              (FAILOVER=ON)
              (ADDRESS = (PROTOCOL = TCP)(HOST = 10.132.111.14)(PORT = 1521))
           )
           (CONNECT_DATA =
             (SERVICE_NAME = bomc)
             (INSTANCE_NAME = bomc)
             (FAILOVER_MODE=(TYPE=session)(METHOD=basic)(RETRIES=4)(DELAY=1))
           )
        )
        (DESCRIPTION =
           (ADDRESS_LIST =
              (LOAD_BALANCE=OFF)
              (FAILOVER=ON)
              (ADDRESS = (PROTOCOL = TCP)(HOST = 10.112.11.161)(PORT = 1521))
           )
           (CONNECT_DATA =
              (SERVICE_NAME = bomc)
              (INSTANCE_NAME = bomc)
              (FAILOVER_MODE=(TYPE=session)(METHOD=basic)(RETRIES=4)(DELAY=1))
           )
        )
       
  )
 
关于其中的配置参数作用请查相关资料!
 
3. java jdbc连接
其中URL写为java:oracle:oci:@ha_db


 

java oracle thin 和 oci 连接方式实现多数据库的故障切换,布布扣,bubuko.com

java oracle thin 和 oci 连接方式实现多数据库的故障切换

标签:java   oracle thin oci   oracle thin   oracle oci   数据库故障切换   

原文地址:http://blog.csdn.net/shefron/article/details/38562645

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!