Popular Posts

July 16, 2024

Explain What are the Different Types Of JDBC Drivers

 

JDBC (Java Database Connectivity) drivers are essential for enabling Java applications to connect to databases. There are four main types of JDBC drivers, each with its own characteristics:

1. Type 1: JDBC-ODBC Bridge Driver

  • Description: This driver translates JDBC calls into ODBC calls and then sends them to the ODBC driver.
  • Advantages: Easy to use with existing ODBC-compliant databases.
  • Disadvantages: Performance overhead due to the conversion layer; not suitable for production use; deprecated in Java 8.

2. Type 2: Native-API Driver

  • Description: This driver converts JDBC calls into database-specific native calls using the database's client-side libraries.
  • Advantages: Better performance than Type 1 due to native API usage.
  • Disadvantages: Requires native libraries for each database, making it less portable; installation of native drivers on client machines is needed.

3. Type 3: Network Protocol Driver

  • Description: This driver translates JDBC calls into a database-independent protocol, which is then converted to the database-specific protocol by a middleware server.
  • Advantages: No client-side installation required; portable; can connect to multiple databases.
  • Disadvantages: Requires a middleware server, which can introduce additional complexity and potential performance bottlenecks.

4. Type 4: Thin Driver

  • Description: This driver converts JDBC calls directly into the database-specific protocol using Java. It does not require any native libraries.
  • Advantages: High performance, platform-independent, no additional installations required on the client; most widely used in production environments.
  • Disadvantages: Limited to one specific database type; requires development of a new driver for each database.

Each type of JDBC driver has its use cases, and the choice often depends on specific application requirements, performance considerations, and deployment environments.


What Are JDBC Drivers?

JDBC API not directly communicate with the database. It uses JDBC driver of the database to interact with the database. JDBC driver is a software component provided along with the database which is required by the JDBC API to interact with the database. Each database will have its own JDBC driver.

In simple terms, JDBC drivers are nothing but the implementations of interfaces provided in the JDBC API (java.sql and javax.sql packages) with respect to a particular database. These implementations are bundled in a JAR file and supplied along with the database. These implementations are used by the JDBC API to interact with that database.

Types Of JDBC Drivers :

There are 4 types of JDBC drivers:

1) Type 1 JDBC Driver / JDBC-ODBC Bridge Driver

2) Type 2 JDBC Driver / Native API Driver

3) Type 3 JDBC Driver / Network Protocol Driver

4) Type 4 JDBC Driver / Native Protocol Driver

1) Type 1 JDBC Driver / JDBC-ODBC Bridge Driver

JDBC Drivers provide the bridge between JDBC and ODBC API and hence the name ‘JDBC-ODBC Bridge Drivers’. This type of drivers translate all JDBC calls into ODBC calls and sends them to ODBC driver which interacts with the database. These types of drivers are slowest of all types. Because, all JDBC calls will go to the ODBC driver through the bridge and then to database. So it is time consuming and raises the performance issues. This type of drivers are not recommended for high transaction java applications. And also this driver is not entirely written in java language. It causes the portability issues.

Explain What are the Different Types Of JDBC Drivers
Explain What are the Different Types Of JDBC Drivers


Below diagram shows how JDBC-ODBC bridge driver is used to interact with the database.

Advantages:

easy to use.
can be easily connected to any database.

Disadvantages:

Performance degraded because JDBC method call is converted into the ODBC function calls.
The ODBC driver needs to be installed on the client machine.

2) Type 2 JDBC Driver / Native API Driver

JDBC Driver translates all JDBC method calls into database specific calls using native API of the database. Its performance is slightly better than the Type 1 driver as communication layer is reduced in this driver. But, like Type 1 Driver, it is also not entirely written in java language. This causes the portability issues. And also this driver is database specific. So once you switch from one database to another, you have to change the driver. That is also one of the disadvantage of this driver.

Below diagram shows how Native API Driver works.

Advantage:

performance upgraded than JDBC-ODBC bridge driver.

Disadvantage:

The Native driver needs to be installed on the each client machine.
The Vendor client library needs to be installed on client machine.

3) Type 3 JDBC Drivers / Network Protocol Driver

JDBC Drivers make use of middle ware or application server that translates all JDBC calls into database specific calls. One of the main advantage of this driver is that it is entirely written in java language. So no portability issues. But it is costly as extra application server or middle ware component has to be maintained.

Below diagram shows how Network Protocol Driver works.

Advantage:

No client-side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc.

Disadvantages:

Network support is required on client machine.
Requires database-specific coding to be done in the middle tier.
Maintenance of Network Protocol driver becomes costly because it requires database-specific coding to be done in the middle tier.

4) Type 4 JDBC Drivers / Native Protocol Drivers

JDBC Driver is also called Thin Driver as it directly converts JDBC calls into database specific calls. This driver is most popular among all 4 types of JDBC drivers. This driver is preferred over Type 3 Driver as it removes extra layer of communication (Application Server / Middle ware) and this makes it faster than the Type 3 JDBC Driver. And also, like Type 3 JDBC Driver, It is also entirely written in java language and hence portable.

Advantage:

Better performance than all other drivers.
No software is required at client side or server side.

Disadvantage:

Drivers depends on the Database.


No comments:
Write comments