JDBC - Type 2 Driver

Last Updated : 24 Apr, 2026

JDBC Type 2 Driver, also known as the Native API Driver, converts JDBC calls into database-specific native API calls. These calls are directly understood by the database using native libraries installed on the client machine.

  • Uses database-specific client libraries
  • Requires native binaries on client machine
  • Platform dependent

Note : It's like the bridge driver or Type-1 driver, Also this driver requires some binary code to be loaded on each client machine.

Architecture

JDBC Type-2 Driver architecture involves converting JDBC calls into database-specific native API calls, where the driver interacts with the database through client-side native libraries installed on the system.

Working of Type 2 Driver

  • JDBC driver directly talks to DB client using native API
  • It required native API to connect to DB client it is also less portable and platform dependent
  • Type 2 drivers convert JDBC calls into database-specific calls i.e. this driver is specific to a particular database.
  • Like Type 1 drivers, it’s not written in Java Language which forms a portability issue.
  • If we change the Database we have to change the native API as it is specific to a database.
  • Type-2 drivers are rarely used in modern applications, as Type-4 (Thin) drivers are preferred due to better portability and ease of deployment
  • Type-2 drivers are platform-dependent and require native database libraries, which reduces portability and makes them less suitable for modern applications.

Example

Java
import java.sql.*;

public class Type2Example {
    public static void main(String[] args) {
        try {
            // Load Native API Driver (example for Oracle)
            Class.forName("oracle.jdbc.driver.OracleDriver");

            // Establish connection
            Connection con = DriverManager.getConnection(
                "jdbc:oracle:oci:@localhost:1521:xe", "username", "password");

            // Create statement
            Statement stmt = con.createStatement();

            // Execute query
            ResultSet rs = stmt.executeQuery("SELECT * FROM students");

            // Process result
            while (rs.next()) {
                System.out.println(rs.getInt(1) + " " + rs.getString(2));
            }

            // Close connection
            con.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Advantages

  • Better performance than Type-1 driver due to direct use of native APIs
  • Faster execution as it avoids ODBC layer
  • Direct interaction with database-specific libraries

Disadvantages

  • Platform dependent
  • Requires native library installation
  • Not portable across different databases
  • Not thread-safe
  • Needs driver change when database changes

Note : This type of driver converts the calls that a developer writes to the JDBC application programming interface into calls that connect to the client machine’s application programming interface for a specific database, such as IBM, Informix, Oracle or Sybase.

Comment