The URI Method for connecting to the Oracle cluster by using thin in Java was recorded last time. I have not tested the method, but I found that the OCI (Oracle call interface) is more stable, and finally decided to use this method. Follow these steps to complete environment Configuration:
1. Install the Oracle client and create the configuration file tnsnames. ora in the installation directory as prompted. For details, refer to the following:
Dbcenter =
(Description =
(Address_list =
(Address = (Protocol = TCP) (host = db1_vip) (Port = 1521 ))
(Address = (Protocol = TCP) (host = db2_vip) (Port = 1521 ))
(Load_balance = yes)
)
(CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = dbcenter)
)
)
Dbcenter1 =
(Description =
(Address_list =
(Address = (Protocol = TCP) (host = db1_vip) (Port = 1521 ))
)
(CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = dbcenter)
(Instance_name = dbcenter1)
)
)
Dbcenter2 =
(Description =
(Address_list =
(Address = (Protocol = TCP) (host = db2_vip) (Port = 1521 ))
)
(CONNECT_DATA =
(Server = dedicated)
(SERVICE_NAME = dbcenter)
(Instance_name = dbcenter2)
)
; MSO-bidi-font-family: "Times New Roman"; MSO-font-kerning: 1.0pt; MSO-ANSI-language:
En-US; MSO-Fareast-language: ZH-CN; MSO-bidi-language: AR-SA '>)
; MSO-bidi-font-family: "Times New Roman"; MSO-font-kerning: 1.0pt; MSO-ANSI-language:
En-US; MSO-Fareast-language: ZH-CN; MSO-bidi-language: AR-SA '> 2. add IP configuration in the C:/Windows/system32/Drivers/etc/hosts file.
3. Use JDBC: oracle: OCI: @ dbcenter in the code to connect to the Oracle cluster.
The connection is normal after testing.