Javaoraclethin and oci Connection Methods for multi-database failover I. thin method is simple and easy to use. The URL is jdbc: oracle: thin: @ (DESCRIPTION (LOAD_BALANCEon) (ADDRESS (PROTOCOLTCP) (HOST127.0.0.1) (PORT1521) (ADDRESS (PROTOCOLTCP) (HOST10.132.
Java oracle thin and oci Connection Methods for multi-database failover I. thin is a simple and easy to use method. 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.
Java oracle thin and oci Connection Methods for multi-database failover
I. thin Method
This method is simple and easy to use. 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 )))
LOAD_BALANCE = on indicates that the load is enabled, and java creates a session connection randomly;
LOAD_BANLANCE = off indicates that the load is disabled. java creates Session connections in sequence and only
When the first database fails and cannot be connected, the second database is selected for session connection.
Ii. oci Mode
In windows:
1. Install the oracle client on the local machine where the specific program is deployed: the path isORALC_HOME;
2. append in the PATH of the system environment variable; % ORACLE_HOME %/bin;
3. Add in system environment variablesNLS_LANGThe character set of the system environment variable is consistent with that of the database and client, for example:NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
4. If CLASSPATH is configured in the system environment variable, append it to the variable; % ORACLE_HOME %/lib
5. Install the jdbc Driver (ORACLE_HOME/jdbc/lib/ojdbc *. jar) in the oracle client to your project.
In unix or linux:
1. Install the oracle client on the local machine where the specific program is deployed: the path isORALC_HOME;
2. Set the PATH of the system environment variable as follows:
PATH = $ ORACLE_HOME/bin: $ PATH
Export PATH
3. Set the system environment variable LD_LIBRARY_PATH as follows:
LD_LIBRARY_PATH = $ ORACLE_HOME/lib: $ LD_LIBRARY_PATH
Export LD_LIBRARY_PATH
4. Set in system environment variablesNLS_LANGVariable. Its Character Set is consistent with that of the database and client, for example:
NLS_LANG = "SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
Export NLS_LANG
5. The jdbc Driver (ORACLE_HOME/jdbc/lib/ojdbc *. jarIn your project to maintain consistency with the database. Otherwise, exceptions that cannot connect to the local method may occur.
The configuration of an oracle client TNSNAMES. ORA file is as follows:
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 ))
)
)
)
For more information about the role of configuration parameters, see
Then, when the Java program jdbc oci is connected, the url is writtenJava: oracle: oci: @ ha_dbYou can.