Types of JDBC drivers in java
In previous post What is Java Database Connectivity (JDBC)? JDBC introductory post we talked about what is JDBC API and we also knew JDBC driver is the one who helps JDBC to connect with database
In this post we will talk about all the types of drivers available in JDBC and which driver we should use in different scenarios.
JDBC driver is a software component that enables Java applications to communicate with the database by implementing the defined interfaces in the JDBC API.
There are 4 types of JDBC drivers:
- DBC-ODBC bridge Driver.
- Native-API driver.
- Network-Protocol driver (Middleware driver)
- Database-Protocol driver (Pure Java driver) or thin driver
Above JDBC drivers are also known as Type 1, Type 2, Type 3 and Type 4 driver
Now let’s explore above all JDBC driver in little more detail.
JDBC-ODBC bridge Driver
In JDBC-ODBC bridge driver or Type 1 driver, a JDBC bridge is used to access the ODBC drivers installed on each client machine. To use ODBC, it is necessary to configure the Data Source Name (DSN) on your system that represents the target database.
When Java was launched, it was a useful driver because most of the databases used to support ODBC access, but now this type of driver is recommended only for experimental use or when no other option is available.
JDBC-ODBC Bridge which comes with JDK 1.2 is a good example of such driver.
NOTE: JDBC-ODBC bridge driver has been removed in java 8
Java 8 does not support the JDBC-ODBC Bridge driver. Oracle recommends that we should use JDBC drivers provided by the vendor of your database instead of using JDBC-ODBC Bridge.
Disadvantages of this driver is that Performance degraded due to JDBC method call is converted into the ODBC function calls and The ODBC driver needs to be installed on the client machine.
Native-API driver also known as The JDBC type 2 driver, is a database driver implementation that uses the client-side libraries of the database. The driver converts JDBC method calls into native API(C/C++) calls of the database. For example: Oracle OCI driver is a type 2 driver.If we look into the performance it has good performance than JDBC-ODBC bridge driver because it eliminates ODBC function call overhead.
Disadvantage of this type of driver is that if we change our database we have to change the native API as well because it is specific to a database.this driver is almost obsoleted now.
The good example of this type of driver is Oracle Call Interface (OCI) driver.
Network-Protocol driver (Middleware driver)
The Network Protocol driver is also known as Type 3 driver.This driver basically follows three-tier approach to access databases.It uses middleware (application server) that converts JDBC calls directly or indirectly into the vendor-specific database protocol.
This driver differs from the type 4 driver in that the protocol conversion logic resides not at the client, but in the middle-tier. The type 4 drivers and type 3 driver are written entirely in Java language.
The client-side JDBC driver may be used for multiple databases. It basically depends on the number of databases the middleware has been configured to support. The type 3 driver is platform-independent because platform-related differences are taken care by the middleware. One main advantage we have in type 3 driver is that making use of the middleware provides additional advantages of security and firewall access.
Database-Protocol driver (Pure Java driver) or thin driver.
This is also known as Type 4 driver is a database driver implementation that converts JDBC calls directly into a vendor-specific database protocol.
Written completely in Java, type 4 drivers are thus platform independent. This driver basically installs inside the Java Virtual Machine of the client because of this reason this provides better performance compare to the type 1 and type 2 drivers as it does not have the overhead of conversion of calls into ODBC or database API calls. Unlike the type 3 drivers, it does not need associated software (application server) to work.
That’s all about this topic What is Java Database Connectivity (JDBC)?
You May Also Like:
What is Java Database Connectivity (JDBC)?
JDBC MySQL database Connection example
JDBC database connection using property resource(property file)
CRUD(Create,Read,Update and Delete) Operation using JDBC Statement
Reading data from database using JDBC Statement
CRUD(Create,Read,Update and Delete) Operation using JDBC PreparedStatement
If you have any feedback or suggestion please feel free to drop in blow comment box.