RAC的配置如下:
node1:ip地址192.168.10.1,实例名:rac1,主机名:x1
node2:ip地址192.168.10.2,实例名:rac2,主机名:x2
RAC服务名为x
配置过程如下:
1、google了一下,发现Bea网站提供的连接RAC方法最多,拷贝了如下的jdbcURL:
jdbc:oracle:thin:@(description=(address_list= (address=(host=192.168.10.1) (protocol=tcp)(port=1521))(address=(host=192.168.10.2)(protocol=tcp) (port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name= x)))
但是出现如下错误:
Io 异常: NL Exception was generated;
2、又从网上google、baidu一番,虽然找到n方法,但就是连不上;
3、无奈之中,打开数据库tnsname.ora,发现其中的配置如下:
x=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = x1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = x2)(PORT = 1521))
(LOAD_BALANCE = yes)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = x)
)
)
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = x1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = x2)(PORT = 1521))
(LOAD_BALANCE = yes)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = x)
)
)
于是将jdbcUR修改成:
jdbc:oracle:thin:@(description=(address_list= (address=(host=x1) (protocol=tcp)(port=1521))(address=(host=x2)(protocol=tcp) (port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name= x)))
测试一下,结果竟然成功了;初步认为是:数据库服务采用主机名,而在jdbcURL中采用ip地址的方式就会出现NL Exception的问题;
建议:对于连接RAC有问题的情况,最好使用tnsnames.ora中连接字符串进行连接;
DEVDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ds1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = ds2-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = devdb)
)
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ds1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = ds2-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = devdb)
)
)
实际的客户端连接时要将ds1-vip和ds2-vip换为数据库的虚拟ip地址