JDBC连接oracle RAC数据库配置
RAC的配置如下:
node1:ip地址192.168.60.132,实例名:rac1,主机名:rac1
node2:ip地址192.168.60.144,实例名:rac2,主机名:rac2
RAC服务名为oratest
我的应用服务器为apache+tomcat
配置过程如下
1、搜索了一下,发现提供的连接RAC方法很多,拷贝了如下的jdbcURL:
jdbc:oracle:thin:@(description=(address_list= (address=(host=192.168.60.132) (protocol=tcp)(port=1521))(address=(host=192.168.60.144)(protocol=tcp) (port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name= oratest)))
但是tomcat报出如下错误:
Io 异常: NL Exception was generated;
2、又从网上google、baidu一番,虽然找到n方法,但就是连不上,总是提示这个错误;
3、无奈之中,打开数据库tnsname.ora,发现其中的配置如下:
oratest=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2)(PORT = 1521))
(LOAD_BALANCE = yes)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oratest)
)
)
于是将jdbcUR修改成:
jdbc:oracle:thin:@(description=(address_list= (address=(host=rac1) (protocol=tcp)(port=1521))(address=(host=rac2)(protocol=tcp) (port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name= oratest)))
测试一下,结果竟然成功了;
初步认为是:数据库服务采用主机名,而在jdbcURL中采用ip地址的方式就会出现NL Exception的问题;
建议:对于连接RAC有问题的情况,最好使用tnsnames.ora中连接字符串进行连接;