Oracle JDBC connection: OCI and thin

Source: Internet
Author: User
Tags oracle database installation

OCI and thin are two sets of Java access methods provided by Oracle to access the Oracle database.

Thin is a thin client connection method. In this connection mode, you do not need to install the Oracle client. You only need to include the JDBC driver jar package in classpath. Thin is an Oracle database access interface written purely in Java.
OCI
Is a fat client connection method, that is, to use this connection method, you need to install the Oracle client. OCI is an oracle call
The abbreviation of the interface is that Oracle provides an access interface, that is, to use Java to call the local Oracle client and then access the database. The advantage is that the speed
Fast, but you need to install and configure the database.

The following points can be summarized from relevant materials:
1. in terms of usage, OCI must install the Oracle client on the client or connect to the database, but thin is not required. Therefore, thin is more convenient to use, which is also a common reason for thin.
2.
In principle, thin implements c/s communication of TCP/IP in pure Java. In OCI mode, the client calls C through Native Java method.
The library accesses the server, and the C library is OCI (Oracle called
Therefore, this OCI always needs to be installed with the Oracle client (from oracle10.1.0, the OCI instant is provided separately
Client. You do not need to install the client completely)
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.

 

Switching from the thin driver to the OCI driver is easy to configure. You only need to replace the connection string Java: oracle: thin: @ hostip: 1521: Instance name with Java: oracle: OCI @ local service name. For example
JDBC: oracle: thin: @ 10.1.1.2: 1521: shdb
Change
JDBC: oracle: oci8: @ shdb
However

Here, this machine needs to install the Oracle database client and configure the local service name. At the same time, you need to specify the nls_lang environment variable, which is used to control the display of the Client

Character Set and localization habits used in Oracle Database Data. Generally, If you specify the nls_lang character set as the character set used by the database, Java will not display garbled characters.
.
There are two options for installing the Oracle database client. One is to use the Oracle database installation CD to install the corresponding version of the Oracle client. The second is to download the real-time client from which Oracle is extracted. The real-time client does not need to be installed. Just unzip the downloaded package.
To enable Java Web to normally access Oracle through the OCI driver, you also need to configure relevant variables correctly on the client. The main features are as follows:
For Windows and Oracle clients:
1. Add % ORACLE_HOME % lib to the path environment variable.
2. Add % ORACLE_HOME % jdbclibclasses12.jar to the classpath environment variable. You can also copy classes12.jar to the commanlib directory of Tomcat.
For Windows and Oracle Real-Time clients (assuming that the real-time client is decompressed on the d disk ):
1. Add D: instantclient_10_2 to the path environment variable.
2. Add D: instantclient_10_2classes12.jar to the classpath environment variable. You can also copy classes12.jar to the commanlib directory of Tomcat.

For Linux systems and Oracle clients:
1. Add the. bash_profile file in the user's home directory using Tomcat
Exprot ORACLE_HOME =/u01/APP/Oracle/product/9.2.0.4
Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib
2. Copy classes12.jar to the commanlib directory of Tomcat.

  
For Linux systems and Oracle Real-Time clients:
1. Add the. bash_profile file in the user's home directory using Tomcat
Exprot ORACLE_HOME =/instantclient_10_2
Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib
2. Copy classes12.jar under the instantclient_10_2 directory to the commanlib directory of Tomcat.

  
For example, if one Tomcat contains several applications and each application needs to connect to the Oracle database, pay attention not-
Put the Oracle classes12.jar/ZIP file under the INF/lib directory. Instead, put the classes12.jar/ZIP file in the Tomcat
Under the common/lib directory. Otherwise, the ojdbclib9/10 library will be reloaded.

Using the Oracle Real-time client, you can create a tnsnames. ora directory under the instantclient_10_2 directory to add a connection string, for example:

Shdb = (description = (address_list = (address = (Protocol = TCP) (host =
10.1.1.236) (Port = 1521) (CONNECT_DATA = (SERVICE_NAME = shdb.

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.