java oracle thin 和 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 连接方式实现多数据库的故障切换,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。