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.

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.
Role of JDBC in Java Database Connectivity
The role of JDBC in Java is to provide a standard interface that allows Java applications to interact with relational databases. JDBC (Java Database Connectivity) acts as a bridge between Java code and databases like MySQL, Oracle, or PostgreSQL. Below are the three key roles JDBC performs in database operations:
Type 1: Establishing a Connection with the Database
JDBC connectivity in Java begins with creating a connection between the Java application and the database. This is achieved using the DriverManager class and connection strings. Developers specify the database URL, username, and password to initiate the connection.
Example:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "user", "password");
This step is crucial for any Java database connection using JDBC and forms the base for all subsequent database interactions.
Type 2: Executing SQL Queries from Java
Once the connection is established, JDBC allows the execution of SQL statements through interfaces like Statement, PreparedStatement, and CallableStatement. This enables developers to run SELECT, INSERT, UPDATE, or DELETE queries directly from Java code.
Example:
PreparedStatement ps = con.prepareStatement("INSERT INTO students VALUES (?, ?)");
ps.setInt(1, 101);
ps.setString(2, "John");
ps.executeUpdate();
This demonstrates JDBC query execution for inserting records into a database table.
Type 3: Retrieving and Processing Results
After executing a query, JDBC retrieves results using the ResultSet interface. Developers can iterate over the result set row by row to fetch and process database records within Java.
Example:
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("name"));
}
This makes it clear how JDBC works in Java to pull data from a database and process it dynamically.
Types of JDBC Driver
Based on the functionality and the architecture, all the Drivers are classified into four types:
- Type-1 Driver or JDBC-ODBC bridge driver
- Type-2 Driver or Native-API driver
- Type-3 Driver or Network Protocol driver
- 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.




