JDBC Tutorial

Type-1 Driver

These are developed by SUN micro systems. The name of the Type-1 driver is JdbcOdbcDriver. The driver JdbcOdbcDriver is found in a package called sun.jdbc.odbc. Using this driver we can develop only 2-tier applications (a java program and database). This type of driver is purely implemented in 'C' language and this driver is platform dependent in nature.

Loading the drivers:

Loading the drivers is nothing but creating an object of appropriate Driver class. In order to load the drivers we have two ways, they are:

1) Using Class.forName:

This technique uses the method forName (String) from java.lang.Class. Calling forName (String) instructs the JVM to find, load, and link the class file identified by the String parameter. As part of initialization, the driver class will register itself with the driver manager. Thus your code does not need to create an instance of the class, nor does it need to call the registerDriver (Driver) method. The JVM creates the instance for you, and the driver itself does the registration.

For example:

Class.forName (Sun.jdbc.odbc.JdbcOdbcDriver);
Class.forName (oracle.jdbc.driver.OracleDriver);

2) Using DriverManager.registerDriver:

DriverManager class contains the following method which will load the driver at runtime.

For example:

public static void registerDriver (java.sql.Driver);

Driver is an interface which is implemented by various database vendors and server vendors. If the appropriate driver object is created that driver object will act as a middle layer between program and database. If the driver is not found we get an exception called java.sql.SQLException

For example:

DriverManager.registerDriver (new Sun.jdbc.odbc.JdbcOdbcDriver);
[for oracle driver is - classes111.jar]