JDBC连接Oracle RAC集群问题
2010-02-21 11:29
You would need to configure your tnsnames.ora with the following information in the following way: RAC_DB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = node1)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = node2)(PORT = 1521)) (LOAD_BALANCE = yes) (FAILOVER = on) ) (CONNECT_DATA = (SERVICE_NAME = RAC_DB) (FAILOVER_MODE = (TYPE = SELECT) (METHOD = BASIC) (RETRIES = 20) (DELAY = 10) ) ) ) Now if you start a SQL*PLUS session, then you should see a connection on the node1 instance. If you start another SQL*PLUS session, then Oracle should connect you to the node2 instance (automatic load balancing). It's actually pretty cool to see the first time. To pass this same information to the Oracle's JDBC thin driver, you essentially concatenate a shorten version of the tnsnames information above and pass this to the driver. String userid = "scott"; String password = "tiger"; String tnsnames_info = "(DESCRIPTION=(ADDRESS_LIST=" + "(ADDRESS=(PROTOCOL=TCP)(HOST=node1)(PORT=1521))" + "(ADDRESS=(PROTOCOL=TCP)(HOST=node2)(PORT=1521))" + "(LOAD_BALANCE=yes)(FAILOVER=on))" + "(CONNECT_DATA=(SERVICE_NAME=rac_db)))" ; String url = "jdbc:oracle:thin:@" + tnsnames_info; DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); Connection dbConnection = DriverManager.getConnection(url, userid, password);