Home  >  Article  >  Database  >  javaoraclethin和oci连接方式实现多数据库的故障切换

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

WBOY
WBOYOriginal
2016-06-07 15:59:531309browse

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)) (CON

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn