Java Database Connectivity(JDBC) defines how a java program can communicate with a database. JDBC API has two major packages java.sql and javax.sql.
There are 4 types of JDBC drivers available.
1) Type 1 Driver- the JDBC-ODBC bridge :
The JDBC type 1 driver, also known as the JDBC-ODBC bridge is a database driver implementation that the ODBC driver to connect to the database. The driver converts JDBC method calls into ODBC function calls. The bridge is usually used when there is no pure-Java driver available for a particular database.
The driver is implemented in the sun.jdbc.odbc.JdbcOdbcDriver class .
The driver is platform-dependent as it makes use of ODBC which in turn depends on native libraries of the operating system.
Almost any database for which ODBC driver is installed, can be accessed.
a) Performance overhead since the calls have to go through the JDBC overhead bridge to the ODBC driver.
b) The ODBC driver needs to be installed on the client machine
c) considering the client-side software needed, this might not be suitable for applets.
2) Type 2 Driver - the Native-API Driver :
The JDBC type 2 driver, also known as the Native-API driver is a database driver implementation that uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API.
The type 2 driver is not written entirely in Java as it interfaces with non-Java code that makes the final database calls.
A native-API partly Java technology-enabled driver converts JDBC calls into calls on the client API for ORACLE, DB2 or other . Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.
However the type 2 driver provides more functionality and performance than the type 1 driver as it does not have the overhead of the additional ODBC function calls.
Better performance than Type 1 since no jdbc to odbc translation is needed
a) The vendor client library needs to be installed on the client machine.
b) Cannot be used in internet due the client side software needed
c) Not all databases give the client side library
3) Type 3 driver - the Network-Protocol Driver:
The JDBC type 3 driver, also known as the network-protocol driver is a database driver implementation which makes use of a middle-tier between the calling program and the database. The middle-tier (application server) converts JDBC calls directly or indirectly into the vendor-specific database protocol.
a) Since the communication between client and the middleware server is database independent, there is no need for the vendor db library on the client machine.
b) The Middleware Server (Can be a full fledged J2EE Application server) can provide typical middleware services like caching (connections, query results, and so on), load balancing etc.
a) Requires database-specific coding to be done in the middle tier.
b) An extra layer added may result in a time-bottleneck
4) Type 4 - the Native-Protocol Driver :
The JDBC type 4 driver, also known as the native-protocol driver is a database driver implementation that converts JDBC calls directly into the vendor-specific database protocol.
The type 4 driver is written completely in Java and is hence platform independent. It is installed inside the Java Virtual Machine of the client. It provides better performance over the type 1 and 2 drivers as it does not have the overhead of conversion of calls into ODBC or database API calls. Unlike the type 1 and 2 drivers, it does not need associated software to work..
a) These drivers don't translate the requests into db request to ODBC or pass it to client api for the db, nor do they need a middleware layer for request indirection. Thus the performance is considerably improved.
b) Web application mainly used this driver.
At client side, a separate driver is needed for each database. ex- classes12.zip (for ORACLE)