Java Oracle thin and OCI connectivity for failover of multiple databases
First, Thin way
This method is easy to use and is not uncommon.
The URL is
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=busi_db)))
The load_balance=on indicates that the load is on, and Java creates the session connection in random way;
Load_banlance=off indicates that the load is closed, and Java creates the session connection in a sequential fashion, with only
The second database is selected for session connection only if there is a problem with the first database that cannot be connected.
Ii. mode of OCI
under Windows system :
1. Detailed program deployment of the native need to install OracleClient: path is oralc_home;
2. In the system environment variable path append ;%O Racle_home%/bin .
3. Add the Nls_lang system environment variable to the system environment variable whose character set is consistent with the database and client as follows:Nls_lang=simplified Chinese_china. ZHS16GBK
4. If CLASSPATH is configured in the system environment variable, append to the variable ;%O Racle_home%/lib
5. OracleClient the JDBC driver (Oracle_home/jdbc/lib/ojdbc*.jar) to your own project project.
Under UNIX or Linux systems:
1. Detailed program deployment of the native need to install OracleClient: path is oralc_home;
2. The System environment variable path setting such as the following:
Path= $ORACLE _home/bin: $PATH
Export PATH
3. System environment variables Ld_library_path settings such as the following:
Ld_library_path= $ORACLE _home/lib: $LD _library_path
Export Ld_library_path
4. Set the nls_lang variable in the system environment variable whose character set is consistent with the database and client as follows:
nls_lang= "Simplified Chinese_china. ZHS16GBK "
Export Nls_lang
5. OracleClient's own JDBC driver (Oracle_home/jdbc/lib/ojdbc*.jar) is tested in its own project to maintain consistency with the database. Otherwise, easy appears unable to connect the exception of the local method.
Here is a list of configurations for a Oracleclienttnsnames.ora file such as the following:
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 = DB1)
(instance_name = DB1)
(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 = DB2)
(instance_name = DB2)
(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 = db3)
(instance_name = db3)
(Failover_mode= (type=session) (Method=basic) (retries=4) (Delay=1))
)
)
)
Please check the relevant information for the function of the configuration parameter.
Then, when the Java program JDBC OCI is connected, the URL is written as java:oracle:oci: @ha_db can.
Java Oracle thin and OCI connectivity for failover of multiple databases