Oracle's OCI and thin differences

Source: Internet
Author: User
Tags tomcat server

When I saw the configuration of the Tomcat data source today, I remembered this question, and I didn't know what thin was at first.

Database.url=jdbc:oracle:thin:angel/[email Protected]:1530:monitordb

After searching the internet, we get the following results:

Jdbc:oracle is connected to the Oracle database

Thin is a method

Angel/oracle that Angel is the username, Oracle is the password

192.168.55.11 is the computer IP you want to connect to.

1530 is the connecting port of Oracle (1521 appears to be the default port)

Monitordb This is the name of the database.

Here is the article I reprinted, which is about the OCI and thin differences between Oracle in the Tomcat data source:

A few days ago, colleagues ran to tell me that a tomcat server in the computer room with the Oracle database Machine connection is very slow, view the Hibernate log in the console, basically a SQL out to wait 1-2 seconds and then out of the second. But the same program on his own machine Tomcat run, the same is even the database machine, a lot faster, do not appear in front of each execution of 1 SQL card once shell case.

Preliminary analysis, I think it may be network reasons, the machine room two machines connected is not smooth, program and machine poor reasons can be ruled out, the engine room Tomcat machine than we develop a more powerful, and the program in his machine run without problems. So I persuaded him to the computer room to check the network status, but he can not enter, because the management of the room is not.

After a while, he told me that the problem solved, the URL of the database access to change to the OCI way, OCI is a little strange to me, I have been using the thin, also did not think of other connection methods. For OCI I can only think of Oracle's client as if there was a oci or something, and then there were other things out of control.

Today intends to understand the difference, first look at the thin and OCI url wording differences: Jdbc:oracle:thin: @server ip:service jdbc:oracle:oci: @service It seems that OCI is also more concise, IP can be omitted to write.

Then find other differences between OCI and thin, and find the following explanation: reference

Oracle provides four different types of the 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 is similar, some features apply only to JDBC OCI drivers and some apply only to the JDBC Th In driver.

JDBC OCI client-side driver:this is a JDBC Type 2 driver This uses Java native methods to call entrypoints in an Underlyi Ng C Library. That's 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 many other platforms. This means the Oracle JDBC OCI driver are not appropriate for Java applets, because it depends on a C library.

Starting from 10.1.0, the JDBC OCI driver are available for install with the OCI Instant Client feature, which does not req Uire a complete Oracle client-installation. Refer to Oracle call Interface for more information.

JDBC Thin client-side driver:this is a JDBC Type 4 driver This 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 is 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 to any browser as part of a Java application. (Note that if running in a client browser, which browser must allow the applets to open a Java socket connection the Server.)

JDBC Thin server-side driver:this is another JDBC Type 4 driver This 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 ways to connect:

ORALCE provides four types of JDBC driver.

Thin Driver, a 100% Java Driver for client-side use without the Oracle installation, particularly 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 would write:connection conn = Drivermanager.getconnection ("Jdbc:oracle:thin: @myhost: 1521:or CL "," 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 would 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 is Conn Ecting. For example, if you want to connect to the database on host Myhost as user Scott with password Tiger This has a tnsnames E Ntry of myhoststring, enter:connection conn = Drivermanager.getconnection ("Jdbc:oracle:oci8: @MyHostString", "Scott", " Tiger ");

If your JDBC client and Oracle server is running on the same machine, the OCI driver can use IPC (interprocess communicat ION) 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 was for code that runs INS IDE a Oracle server and needs to access a remote server, including Middle-tier scenarios. The Server-side Thin driver type is Thin and there are no difference in your code between using the Thin driver from a Clie NT application or from inside a server. Server-side Internal Driver for code this runs inside the target server, that's, inside the Oracle server that it must AC Cess. The Server-side Internal driver type is KPRB and it actually runs within a default session. You are already "connected". Therefore the connection should never be closed. To access the default connection, Write:DriverManager.getConnection ("JDBC:ORACLE:KPRB:") ; Or:DriverManager.getConnection ("Jdbc:default:connection:");

Can also use the Oracle-specific defaultconnection () method of the Oracledriver class which is generally recommen Ded:oracledriver ora = new Oracledriver (); Connection conn = Ora.defaultconnection ();

Note:you is no longer required to register the Oracledriver class for connecting with the Server-side Internal driver, a Lthough there is no harm in doing so. This was true whether you were using getconnection () or defaultconnection () to make the connection. Any user name or password your include in the URL of string is ignored in connecting to the server default connection. The Drivermanager.getconnection () method returns a new Java Connection object every time call it. Note that although the method was not creating a new physical connection (only a single implicit connection are used), it is Returning a new object. Again, when JDBC code was running inside the target server, the connection is a implicit data channel, not an explicit con Nection instance as from a client. It should never be closed.

This basic understanding of the 1) from the use of the OCI must be installed on the client computer Oracle client or to connect, and thin do not need, so from the use of the thin is more convenient, which is thin more common reasons.

2) In principle, thin is a pure Java implementation of TCP/C communication, and the OCI mode, the client through the native Java method call C library access to the server, and this C library is the OCI (Oracle called interface), so this oci always needs to be installed with the Oracle client (from oracle10.1.0, the OCI Instant client is provided separately, without the need for a full installation client)

3) They are different drive categories, OCI is a class two driver, thin is a four-class driver, but they are functionally not different.

4) Although many people say OCI is faster than thin, but for a long time did not find the relevant test report.

  Warm tips: This content is from the network, only representative personal views, and the position of this site is independent, only for your study and exchange use. Some of the articles may have been reproduced many times, resulting in missing articles, errors or the author of the article is unknown, please understand. If infringement of your rights, please contact us, this site will be processed immediately.

Oracle's OCI and thin differences

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.