配置别名:
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)
)
)
)
JDBC:
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);
Spring:
<bean id="dbcp" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS = (PROTOCOL = TCP)(HOST = 10.200.180.193)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 10.200.180.194)(PORT = 1521))(LOAD_BALANCE = yes)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = cjww)))</value>
<!--
<value>jdbc:oracle:thin:@10.200.180.193:1521:cjww</value>
-->
</property>
<property name="username">
<value>ccs</value>
</property>
<property name="password">
<value>ccs154321</value>
</property>
<property name="defaultAutoCommit">
<value>false</value>
</property>
</bean>