Type I driver

ODBC (Open Database Connectivity) is a C language API. It is a specification provided by Microsoft and can be implemented by any company. The implementoers of this API provides the dll files to the customers. These dll files are called as ODBC drivers. The ODBC drivers internally uses native APIs of the database.
If a JDBC driver is written partly in Java and partly in C and if the C code uses ODBC functions then that driver is called as type I JDBC driver.
Note: Javasoft has implemented a JDBC driver as type I driver as this driver comes with JDK. Here the sample type I driver code.

import java.sql.*;

public class Type1
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //This driver comes with JDK kit
Connection connection = DriverManager.getConnection("jdbc:odbc:oradb","scott","tiger");
System.out.println("Connected...");
}
}
Explanation

The above application uses type I driver provided by Javasoft. Before you run this application, you need to:

  • Install client software
  • Configure client software
  • Install JDBC driver
  • Configure JDBC datasource

Type II driver

Type II driver is not a pure Java driver. As part of type II driver the implementers uses Java code with C code via Java native API. i.e.; it's a Java code which uses the base database API implemented in C language.
Oracle corp. has implemented a type II driver using OCI functions internally (These OCI functions are referred as OCI driver by Oracle corp.).
import java.sql.*;

public class OCI
{
public static void main(String args[]) throws Exception
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = DriverManager.getConnection("jdbc:oracle:oci:@orans","scott","tiger");
System.out.println("Connected...");
//Remaining code...
}
}
The above application uses type II driver provided by Oracle corp. In order to use this driver, you must:
  • Use the jar file (ojdbc14.jar)
  • Install the client software provided by database vendor (this software contains OCI in case of Oracle)
  • Configure the client software

Type III driver

JDBC type III driver layout
Type III driver is a pure Java driver. Type III driver establishes the connection with an application called as net server and the net server connects to the databse server.
Type III drivers are used to access the database servers that are running behind firewalls.
As shown in the above diagram the network administrators can setup the machines mone, mtwo, mthree behind the firewall so that the external machines will not access Oracle server running on mcone.
In this kind of setup to allow the Java applications running on other machines to access the database we must use type III driver.

Type IV driver

If the implementer of the JDBC driver implements everything in Java (Pure Java driver) then the JDBC driver is called as type IV driver.
Oracle corp. has implemented type IV driver apart from type II driver.
import java.sql.*;

public class Thin
{
public static void main(String args[])
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");
System.out.println("Connected...");
}
}