You are on page 1of 21

JDBC DRIVERS

JDBC driver types


Type -1 Bridge driver
Type -2 Native API
Type -3 Network Protocol
Type -4 Native Protocol
JDBC-ODBC bridge driver
 Native-API driver
Oracle Corporation has given 2 JDBC Driver software :
•Oracle OCI Driver – Type-2
•Oracle Thin Driver – Type-4
Oracle OCI Driver – Type-2
The Native API driver uses the client -side libraries of the database.

This driver converts JDBC method calls into native calls of the database API.

In order to interact with different database, this driver needs their local API, that’s
why data transfer is much more secure as compared to type-1 driver.
Network Protocol driver

This network protocol driver uses the middle software like an application server. The JDBC clients use the standard
network sockets to communicate with the middleware application server.

The middleware application server internally converts the JDBC calls to the vendor’s specific database protocol.
Thin driver

This driver interact directly with database. It does not require any native database library, that is why it is
also known as Thin Driver.
Loading the drivers:
Using Class.forName :
Class.forName(Sun.jdbc.odbc.JdbcOdbcDriver);
Class.forName(oracle.jdbc.driver.OracleDriver);

Using DriverManager.registerDriver :
public static void registerDriver (java.sql.Driver);
Obtaining the Connection 
Main Protocol : Sub Protocol : Data Source
       JDBC                  ODBC              Oracle

Connection con1=DriverManager.getConnection (“jdbc : odbc : Access”);

Connection con2=DriverManager.getConnection (“jdbc : odbc : oracle”,”scott”,”tiger”);


Drawbacks of Type-1 Driver :
The Type-1 driver is very slow, because of JDBC-ODBC transactions.
The Type-1 driver is the dependent driver since its depending on ODBC support.
The Type-1 driver is not suitable for real-time applications.
Drawbacks of Type-2 Driver:
The Type-2 driver is both platform and database dependent. Hence it is not suitable
for real-time applications.
This driver is slower than the Type-3 and Type-4 drivers.
Drawbacks of Type-3 Driver :
Since it is a network driver, the client system needs to support the network.
Database specific coding is required for middle layer application. Hence it requires
more maintenance.
Advantages of Type -4
Driver
It is the fastest driver among all types of drivers.
It is a platform independent driver.
This Type-4 driver is suitable for developing real-time applications.
Establish a connection
Create a statement
Execute the query
Process data
Close connection
Establish database connection

DriverManager.getConnection(..);
//type 4 driver
Connection con=DriverManager.getConnection (
“jdbc : oracle : thin :@ localhost : 1521 : chandrashekhar”, “scott”, “tiger”);

String url = "jdbc:oracle:thin:@10.184.132.128:1521:devdb";


Connection conn = DriverManager.getConnection(url,"dev1201st","develop1201");
// Create statement
Statement stmt = conn.createStatement();

// Execute query
ResultSet rs = stmt.executeQuery("select Name from table name");

// Process data
while(rs.next()) {
System.out.println("Artist Name: " + rs.getString("Name"));
}
// Clean up
rs.close();

You might also like