November 28, 2022

JDBC Driver Types

JDBC API in Java programming language provides a standard, universal way to connect to databases. It is the responsibility of different DB vendors to provide the implementation of the interfaces in JDBC API and that implementation by DB vendors is provided as JDBC drivers.

Types of JDBC drivers

Based on these different implementations JDBC drivers are categorized into four types.

  • Type 1 driver: JDBC-ODBC bridge JDBC driver
  • Type 2 driver: Written partly in Java and partly in native code
  • Type 3 driver: Pure Java client and middleware server translating client request to data source.
  • Type 4 driver: Written completely in Java.

Type 1 JDBC Driver

Type 1 JDBC driver implements the JDBC API as a mapping to another data access API, such as ODBC (Open Database Connectivity).

The JDBC-ODBC Bridge driver is an example of type 1 JDBC driver that maps JDBC API requests to ODBC requests.

  1. Type 1 driver is an old driver that is not supported any more by Oracle.
  2. These drivers are not fully written in Java and depends on native library so Type 1 drivers are not portable.
  3. Each JDBC call is mapped to ODBC request and then to DB making it very slow.
Type 1 JDBC driver

Type 2 JDBC Driver

Type 2 JDBC drivers are written partly in the Java programming language and partly in native code. These drivers use native client side libraries specific to the data source to which they connect to.

Oracle's OCI (Oracle Call Interface) client-side driver is an example of a Type 2 driver.

  1. Since native libraries are required so there is platform dependency.
  2. JDBC calls are translated to native calls using native libraries making it a slow driver though not as slow as Type 1 driver.
  3. Native API must be installed on the client machines.
Type 2 JDBC Driver

Type 3 JDBC Driver

In Type 3 JDBC driver client is written in Java which connects to a middleware server using a database independent protocol. JDBC calls from the client are translated by middleware server to the vendor specific DB calls and then forwarded to the data source.

  1. Requires a middleware server.
  2. Since there are two stages; JDBC call to midleware server then vendor specific translation and communication to the DB so the JDBC call processing takes more time.
Type 3 JDBC Driver

Type 4 JDBC Driver

Type 4 JDBC drivers are written completely in Java and don't require any native code libraries or middleware server to sit in the middle. Type 4 drivers implement the network protocol for a specific data source and connect directly to data source.

Type 4 JDBC drivers are also known as thin drivers

  1. Since driver itself implements the vendor specific network protocol so Type 4 drivers are DB specific and generally supplied by the DB vendors.
Type 4 JDBC Driver

That's all for the topic JDBC Driver Types. If something is missing or you have something to share about the topic please write a comment.

You may also like

No comments:

Post a Comment