JDBC API standardizes the way any Java application connects to DB. JDBC API is a collection of interfaces and JDBC drivers implement these interfaces in the JDBC API enabling a Java application to interact with a database.
The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database.
JDBC Driver Types
JDBC drivers can be categorized into four types.
Type 1 JDBC Driver
Type 1 driver is a type of JDBC driver that implements the JDBC API as a mapping to another DB access API.
As example- The JDBC-ODBC Bridge driver that maps JDBC API requests to ODBC requests. Here note that ODBC (Open Database Connectivity) is another standard API for accessing databases which is developed by Microsoft.
Type 1 drivers type are generally dependent on a native library, which limits their portability.
Type 2 JDBC Driver
Type 2 JDBC drivers are written partly in Java and partly in native code. Native client library specific to the data source to which connection is made is used by Type 2 JDBC drivers.
As example- Oracle's OCI (Oracle Call Interface) client-side driver is an example of a Type 2 driver.
Since native code is used by Type 2 drivers, their portability is limited.
Type 3 JDBC Driver
Type 3 JDBC driver has a client that is written in Java and that connects to a middleware server using a database independent protocol. Middleware server in turn communicates with the data source.
The drawback of Type 3 driver is that the middleware server has to be DB specific.
There are two stages in Type 3 JDBC driver. First, where Java application connects to Type 3 driver which in turn connects to middleware server. Its the sever which translates the request to DB specific request making the whole process slower.
Type 4 JDBC Driver
Type 4 JDBC drivers are written completely in Java so no native code library or middleware server is needed, that is why type 4 JDBC drivers are also known as thin drivers. Type 4 drivers themselves implement the network protocol for a specific data source.
Reference: https://docs.oracle.com/javase/tutorial/jdbc/basics/gettingstarted.html
That's all for this topic Types of JDBC Drivers. If you have any doubt or any suggestions to make please drop a comment. Thanks!
>>>Return to Java Advanced Tutorial Page
Related Topics
You may also like-