Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between OCI and THIN driver connection with data source connection between java and oracle XE?

I'm writing the below codes for connection between the java and Oracle 10g XE using 3 way(OCI, THIN and data source), the code is running successfully but don't know difference between the THIN and OCI with data source connection.

1-

public static void main (String args[]) throws SQLException
 {
  OracleDataSource ods = new OracleDataSource();
  ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
  Connection con = ods.getConnection();
  System.out.println("Connected");
  con.close();
 }

2-

public static void main(String args[])
     {
      try
      {
       // load oracle driver
      Class.forName("oracle.jdbc.driver.OracleDriver");
      // connect using Thin driver
      Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","hr","hr");
      System.out.println("Connected Successfully To Oracle");
      con.close();
      }
      catch(Exception ex)
      {
        ex.printStackTrace();
      }
 }

3-

public static void main(String args[])
     {
      try
      {
       // load oracle driver
      Class.forName("oracle.jdbc.driver.OracleDriver");
      // connect using Native-API (OCI) driver
      Connection con = DriverManager.getConnection("jdbc:oracle:oci:@","hr","hr" );
      System.out.println("Connected Successfully To Oracle using OCI driver");
      con.close();
      }
      catch(Exception ex)
      {
        ex.printStackTrace();
      }
 }
like image 825
Tofiq Avatar asked Feb 11 '14 19:02

Tofiq


People also ask

What is Oracle OCI connection?

The OCI connection pooling feature is an Oracle-designed extension. The connection pooling provided by the JDBC OCI driver enables applications to have multiple logical connections, all of which are using a small set of physical connections.

What is an OCI driver?

The OCI driver is a type 2 JDBC driver and uses native code to connect to the database. Thus, it is only an option on platforms that have native Oracle drivers available and it is not a "pure" Java implementation. Oracle's JDBC Thin driver is a type 4 JDBC Driver that uses Java sockets to connect directly to Oracle.

What is thin in Oracle connectivity?

The JDBC Thin driver communicates with the server using TTC, a protocol developed by Oracle to access data from Oracle Database. It can be used for application servers as well as for applets.

What is Oracle thin driver?

Thin driver. It is a pure Java driver used on the client-side, without an Oracle client installation. It can be used with both applets and applications. Oracle Call Interface (OCI) driver. It is used on the client-side with an Oracle client installation.


2 Answers

Oracle provides four types of drivers for their database, but I'll only enumerate the two you asked about.

The OCI driver is a type 2 JDBC driver and uses native code to connect to the database. Thus, it is only an option on platforms that have native Oracle drivers available and it is not a "pure" Java implementation.

Oracle's JDBC Thin driver is a type 4 JDBC Driver that uses Java sockets to connect directly to Oracle. It implements Oracle's SQL*Net TCP/IP protocol directly. Because it is 100% Java, it is platform independent and can also run from an Applet. (not that you should)

like image 128
Elliott Frisch Avatar answered Oct 23 '22 11:10

Elliott Frisch


Both the JDBC thin driver and the JDBC OCI driver speak the same network protocol. From the server standpoint there is no difference between the two. The JDBC thin driver is 100% Java and comes in a single standalone jar (some extra jars will be needed for advanced features). The JDBC OCI driver makes JNI calls to the OCI C client library and hence depends on the Oracle full client to be installed (OCI is also what sqlplus uses). Oracle recommends to use the JDBC thin driver which is what most customers use. It's the fastest driver and the most robust one.

like image 22
Jean de Lavarene Avatar answered Oct 23 '22 10:10

Jean de Lavarene