Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Types of JDBC Driver
2.1.
Type 1 - JDBC-ODBC Bridge Driver
2.1.1.
Advantages of JDBC-ODBC Bridge Driver 
2.1.2.
Disadvantage of JDBC-ODBC Bridge Driver
2.2.
Type 2 - Native-API Driver
2.2.1.
Advantages of Native-API Driver
2.2.2.
Disadvantages of Native-API Driver
2.3.
Type 3 - Network Protocol Driver
2.3.1.
Advantages of Network Protocol Driver
2.3.2.
Disadvantages of Network Protocol Driver
2.4.
Type 4 - Pure Java Direct-to-Database or Thin Driver
2.4.1.
Advantages of Pure Java Direct-to-Database or Thin Driver
2.4.2.
Disadvantages of Pure Java Direct-to-Database or Thin Driver
3.
Frequently Asked Questions
3.1.
Why is JDBC used?
3.2.
What Type of JDBC Driver Should You Use?
3.3.
What is a JDBC Driver?
3.4.
Which JDBC Driver is both database and platform-independent?
3.5.
Which Driver is the slowest?
3.6.
Which Driver is preferred while accessing multiple databases?
4.
Conclusion
Last Updated: May 23, 2024
Easy

JDBC Drivers

Author ANKIT KUMAR
0 upvote
Crack Google SDE interview : Essential projects
Speaker
Saurav Prateek
SDE-2 @
20 Jun, 2024 @ 01:30 PM

Introduction

While communicating with the database, we have to convert Java calls into database-specific calls and database-specific calls into Java calls. To do this task, we require the JDBC Driver.

JDBC Drivers

The JDBC Driver is one of the most crucial parts of the entire JDBC. The JDBC Driver is a software component that enables a Java application to interact with a database.

The important functionalities of the JDBC driver are:

  • It handles the communication with the database server.
  • Instead of directly creating a Driver object, we use the DriverManager object to deal with the Drivers.
  • It also abstracts the details associated with working with the Driver objects.

Types of JDBC Driver

Based on the functionality and the architecture, all the Drivers are classified into four types:

  1. Type-1 Driver or JDBC-ODBC bridge driver
  2. Type-2 Driver or Native-API driver
  3. Type-3 Driver or Network Protocol driver
  4. Type-4 Driver or Pure Java Direct-to-Database or Thin Driver

Let us now see each of these types in detail.

Type 1 - JDBC-ODBC Bridge Driver

The Type-1 Driver converts JDBC calls into ODBC calls, and ODBC Driver converts the ODBC calls into the database-specific calls. Open Database Connectivity (ODBC) is an open standard Application Programming Interface (API) for accessing a database.ODBC is platform dependent as we can use ODBC only for windows platform. Internally the Type-1 Driver takes the support of the ODBC Driver to communicate with the database. The Type-1 Driver is provided by the Sun microsystems as part of the JDK. The figure below shows the architecture of the Type-1 Driver. 

From the figure above, we can see how the Type-1 Driver acts as a bridge between the JDBC and ODBC Driver. Because of this, the Type-1 Driver is also known as the JDBC-ODBC Bridge Driver or simply the Bridge Driver.

Advantages of JDBC-ODBC Bridge Driver 

  • It is easy to use and maintain.
  • We do not have to separately install the Type-1 Driver because it is available as part of the JDK.
  • The Type-1 Driver is database-independent. Type-1 Driver does not communicate with the database directly. Instead, the ODBC Driver does this work.
  • Migrating from one database to another is easy as it is database-independent.

Disadvantage of JDBC-ODBC Bridge Driver

  • It is the slowest Driver among all the Drivers because first, it converts the JDBC calls into the ODBC calls, and then the ODBC Driver converts the ODBC calls into the database-specific calls. This makes the overall process slow.
  • The ODBC Driver is available for the Windows platform only. The Type-1 Driver depends internally on the ODBC Driver; hence it is platform dependent.
  • No support from JDK 1.8 onwards.

Type 2 - Native-API Driver

The architecture of the Type-2 Driver is similar to the Type-1 Driver. However, instead of an ODBC Driver, we have vendor-provided database-specific libraries that can be understood by the database directly. Hence the calls made by the Java application are converted into database-specific native library calls by the Type-2 Driver. The database-specific native library call can be understood by the database because it is provided by the database vendor. The architecture of the Type-2 Driver is shown below.

This Driver is also known as the native API Driver because it internally uses the database-specific native libraries. In order to use the Driver, we have to install the vendor-provided native libraries on the client machine or system.

Also see, Duck Number in Java and Hashcode Method in Java

Advantages of Native-API Driver

  • It is faster as compared to the Type-1 Driver because it converts the function calls only once.
  • ODBC Driver not required.
  • It provides more portability.

Disadvantages of Native-API Driver

  • It is a database-dependent Driver since it internally uses database-specific native libraries to interact with the database. Therefore migrating from one database to another is difficult.
  • It is platform-dependent too.
  • We have to mandatorily install the native libraries on the client machine or system.

Type 3 - Network Protocol Driver

The Type-3 Driver is also known as the network protocol Driver or middleware Driver. The middleware server is responsible for converting the JDBC calls into vendor-specific database calls. 

The architecture of Type-3 Driver is shown below:

Advantages of Network Protocol Driver

  • It is database-independent.
  • It is platform-independent as it is written in Java.
  • The application server performs the necessary tasks; therefore, the client-side library is not required.

Disadvantages of Network Protocol Driver

  • It is expensive because of the maintenance of the network protocol Driver.
  • We need network support on the client machine.

Type 4 - Pure Java Direct-to-Database or Thin Driver

Unlike the previous three types of Drivers, the Type-4 Driver does not require any extra component to communicate with the database. It can directly communicate with the database. 

The architecture of the Type-4 Driver is shown below:

The type-4 Driver is also known as pure Java Driver because it is completely written in Java. This makes it platform-independent. It communicates with the database using the native protocol provided by the database vendor, and therefore it is also known as a native protocol Driver. It is also referred to as a thin Driver.

Advantages of Pure Java Direct-to-Database or Thin Driver

  • It is platform-independent.
  • Since it communicates with the database directly, the overall performance is improved and faster.
  • It does not require any native libraries or middleware servers.

Disadvantages of Pure Java Direct-to-Database or Thin Driver

  • It is database-dependent.


You can also use online java compiler for compile and run the code for good practice.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Frequently Asked Questions

Why is JDBC used?

JDBC (Java Database Connectivity) is used to enable Java applications to interact with a wide range of databases. It provides a standardized API for executing SQL statements, managing connections, and retrieving results.

What Type of JDBC Driver Should You Use?

The choice of JDBC driver depends on the specific requirements of your application, such as performance needs, database type, and network architecture. Common types include Type 4 (pure Java drivers) for direct database connections.

What is a JDBC Driver?

A JDBC driver is a software component that allows Java applications to connect to a database. It translates Java calls into database-specific calls, facilitating communication between the application and the database server.

Which JDBC Driver is both database and platform-independent?

The Type-3 Driver. It is also known as the Network Protocol Driver.

Which Driver is the slowest?

Type-1 Driver is the slowest.

Which Driver is preferred while accessing multiple databases?

The type-3 Driver because Type-3 drivers are fully written in Java, hence they are portable drivers. No client side library is required because of the application server that can perform many tasks like auditing, load balancing, logging etc.

Conclusion

In this article, we have discussed JDBC drivers. JDBC drivers play a crucial role in enabling Java applications to interact seamlessly with various databases. By understanding the different types of JDBC drivers and selecting the appropriate one based on your application's needs, you can ensure efficient database connectivity and performance.

Recommended Readings:

Happy learning!

Previous article
Introduction to JDBC
Next article
JDBC Architecture
Live masterclass