Sunday, October 13, 2024

Types of JDBC Drivers

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 1 JDBC Driver
DB access through Type 1 driver

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 2 JDBC Driver
DB access through Type 2 driver

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 3 JDBC Driver
DB access through Type 3 driver

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.

Type 4 JDBC Driver
DB access through Type 4 driver

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

  1. JDBC Tutorial - Java JDBC Overview
  2. Java JDBC Steps to Connect to DB
  3. ResultSet Interface in Java-JDBC
  4. CallableStatement Interface in Java-JDBC
  5. Data Access in Spring Framework

You may also like-

  1. How HashSet Works Internally in Java
  2. Callable and Future in Java With Examples
  3. Volatile Keyword in Java With Examples
  4. Java Reflection API Tutorial
  5. Dependency Injection in Spring Framework
  6. Spring JdbcTemplate Insert, Update And Delete Example
  7. How to convert Date to String in Java
  8. How to Find Common Elements Between Two Arrays Java Program