Java oracle thin and oci Connection Methods for multi-database failover, thinoci

Source: Internet
Author: User
Tags failover

Java oracle thin and oci Connection Methods for multi-database failover, thinoci

Java oracle thin and oci Connection Methods for multi-database failover

I. thin 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.111.14) (PORT = 1521 ))
(CONNECT_DATA = (SERVICE_NAME = bomc )))

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
1. Install the oracle client on the local machine where the specific program is deployed, specify the bin directory of the oracle client in the PATH, and copy
The jdbc driver in the oracle client is included in your project.

2. Configure the TNSNAMES. ORA file 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 = bomc)
(INSTANCE_NAME = bomc)
(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 = bomc)
(INSTANCE_NAME = bomc)
(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 = bomc)
(INSTANCE_NAME = bomc)
(FAILOVER_MODE = (TYPE = session) (METHOD = basic) (RETRIES = 4) (DELAY = 1 ))
)
)

)

For more information about the role of configuration parameters, see!

3. java jdbc connection
The URL is written as java: oracle: oci: @ ha_db.


 


Java oci connection to the database

OCI is only a connection method. Since you use Java for client programs, why do you need to use Native drivers?
You should use the thin protocol of java: oracle: thin: @ to connect to the database.

OCI itself is prepared for programs such as C ++ and VB. We recommend that you use the thin protocol driver for Java programs.

There are four types of Java drivers: type 1-type 4. Now the type 4 driver has been applied, and almost all vendors provide the type 4 driver, it means that the server and the driver are in the vendor's internal network communication format, and the driver and java program are pure java. The driver of the dependent DLL is type 2, which requires that the DLL of the oracle driver be found in the path of the current path variable or java. library. path parameter. Therefore, if you insist on using the oci driver, you need to add the BIN directory of oracle (there may be other directories, you have to confirm the directory of Oracle DLL anyway) to the PATH variable.

Remember that the dependency between the type 2 driver and the version is large. It may require a DLL of a specific version, but the type 2 does not depend on the dll, between the driver and the server is originally a pure java version, which replaces the DLL function, so the version dependency is small.

Is the path of your-Djava. library. path a real oracle client directory? Can the dll mentioned in be found? What is the result of println (System. getProperty ("java. library. path") in your program?
 
Connection between thin and oci of oracle

Let's take a look at the differences between thin and oci url writing:
Jdbc: oracle: thin: @ server ip: service
Jdbc: oracle: oci: @ service
1) In terms of usage, oci must install the oracle client on the client or connect to it, but thin is not required. Therefore, thin is more convenient to use, this is also a common reason for thin.
2) In principle, thin implements c/s communication with TCP/IP in pure java. In oci mode, the client calls c library through native java method to access the server, this c library is the oci (oracle called interface). Therefore, this oci always needs to be installed with the oracle Client (from oracle10.1.0, the OCI Instant client is provided separately, and the complete Client installation is not required)
3) They are different driver categories, oci is a Class-2 driver, and thin is a Class-4 driver, but they are not functionally different.
4) although many people say that oci is faster than thin, they have not found the relevant test report for half a day.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.