Differences between Oracle OCI and thin

Source: Internet
Author: User
Tags oracle database installation

First, let's take a look at the official explanation:

Oracle provides four different types of JDBC drivers, for use in different deployment scenarios. the 10.1.0 drivers can access Oracle 8.1.7 and higher. while all oracle JDBC drivers are similar, some features apply only to jdbc oci drivers and some apply only
To the JDBC thin driver.

Jdbc oci client-side DRIVER: This is a JDBC Type 2 driver that uses Java Native methods to call entrypoints in an underlying C library. that C library, called OCI (Oracle call interface), interacts with an Oracle database. the jdbc oci driver requires an oracle
Client installation of the same version as the driver.

The use of native methods makes the jdbc oci driver platform specific. oracle supports Solaris, windows, and other platforms. this means that the oracle jdbc oci driver is not appropriate for Java applets, because it depends on a C library.

Starting from 10.1.0, The jdbc oci driver is available for install with the OCI Instant Client feature, which does not require a complete Oracle client-installation. Please refer to Oracle call interface for more information.

JDBC thin client-side DRIVER: This is a JDBC Type 4 driver that uses Java to connect directly to Oracle. it implements Oracle's SQL * Net net8 and TTC adapters using its own TCP/IP based Java Socket implementation. the JDBC thin driver does not require Oracle
Client software to be installed, but does require the server to be configured with a TCP/IP listener.

Because it is written entirely in Java, this driver is platform-independent. the JDBC thin driver can be downloaded into any browser as part of a Java application. (Note that if running in a client browser, that browser must allow the applet to open a Java
Socket connection back to the server .)

JDBC thin server-side DRIVER: This is another JDBC Type 4 driver that uses Java to connect directly to Oracle. this driver is used internally within the Oracle database. this driver offers the same functionality as the client-side JDBC thin Driver (above ),
But runs inside an Oracle database and is used to access remote databases.

Because it is written entirely in Java, this driver is platform-independent. There is no difference in your code between using the thin driver from a client application or from inside a server.

There are several Connection Methods:

Oralce provides four types of JDBC driver.

Thin driver, a 100% Java driver for client-side use without an Oracle Installation, fig with applets. the thin driver type is thin. to connect user Scott with password tiger to a database with Sid (system identifier) orcl through port 1521 of host
Myhost, using the thin driver, you wocould write:

Connection conn = drivermanager. getconnection

("JDBC: oracle: thin: @ myhost: 1521: orcl", "Scott", "Tiger ");

OCI driver for client-side use with an Oracle client installation. the OCI driver type is OCI. to connect user Scott with password tiger to a database with Sid (system identifier) orcl through port 1521 of host myhost, using the OCI driver, you wocould write
:

Connection conn = drivermanager. getconnection

("JDBC: oracle: OCI: @ myhost: 1521: orcl", "Scott", "Tiger ");

Note that you can also specify the database by a tnsnames entry. you can find the available tnsnames entries listed in the file tnsnames. ora on the client computer from which you are connecting. for example, if you want to connect to the database on host myhost
As user Scott with password tiger that has a tnsnames entry of myhoststring, enter:

Connection conn = drivermanager. getconnection

("JDBC: oracle: oci8: @ myhoststring", "Scott", "Tiger ");

If your JDBC client and ORACLE Server are running on the same machine, the OCI driver can use IPC (interprocess communication) to connect to the database instead of a network connection. an IPC connection is much faster than a network connection.

Connection conn = drivermanager. getconnection

("JDBC: oracle: oci8: @", "Scott", "Tiger ");

Server-side thin driver, which is functionally the same as the client-side thin driver, but is for code that runs inside an ORACLE Server and needs to access a remote server, including middle-tier scenarios. the server-side thin driver type is thin and there
Is no difference in your code between using the thin driver from a client application or from inside a server.

Server-side internal driver for code that runs inside the target server, that is, inside the Oracle server that it must access. the server-side internal driver type is kprb and it actually runs within a default session. you are already "connected ". therefore
The connection shoshould never be closed.

To access the default connection, write:

Drivermanager. getconnection ("JDBC: oracle: kprb :");

Or:

Drivermanager. getconnection ("JDBC: Default: Connection :");

You can also use the Oracle-specific defaconnection () method of the oracledriver class which is generally recommended:

Oracledriver ora = new oracledriver ();

Connection conn = ora. defaultconnection ();

Note: you are no longer required to register the oracledriver class for connecting with the server-side internal driver, although there is no harm in doing so. this is true whether you are using getconnection () or defaultconnection () to make the connection.

Any user name or password you include in the URL string is ignored in connecting to the Server default connection. the drivermanager. getconnection () method returns a new Java connection object every time you call it. note that although the method is not creating
A new physical connection (only a single implicit connection is used), it is returning a new object.

Again, when JDBC code is running inside the target server, the connection is an implicit data channel, not an explicit connection instance as from a client. It shoshould never be closed.

Not ugly:

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.

According to your own environment, the OCI configuration method is described below:

A: Install Oracle's cleint.

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 lib directory of resin.

For Linux systems and Oracle Real-Time clients:

1. Add the. bash_profile file in the user's home directory using Resin

Exprot ORACLE_HOME =/opt/product/10.2.0/cleint/

Export LD_LIBRARY_PATH = $ ORACLE_HOME/lib

2. Copy classes12.jar under the instantclient_10_2 directory to the lib directory of resin.

B. To enable the resin to connect to Oracle normally, the Oracle environment variables must be loaded normally. To help me write an OCI. Sh script, you can download it (Change ORACLE_HOME to your own path ),

Run the Script: root @ testserver: [/Home]. OCI. Sh.

C: restart resin.

Resin. conf

<Database>

<JNDI-Name> Oracle </JNDI-Name>

<Driver>

<Type> oracle. JDBC. Pool. oracleconnectionpooldatasource </type>

<URL> JDBC: oracle: oci8: @ fx_rac </URL>

<Password> FX </password>

<User> FX </user>

</Driver>

<Prepared-statement-Cache-size> 8 </Prepared-statement-Cache-size>

<Max-connections> 100 </max-connections>

<Max-idle-time> 30 S </max-idle-time>

</Database>

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.