JDBC Drivers

 

JDBC Drivers

 

 

JDBC stands for Java Database Connectivity. It is a Java API that lets a Java application connect to a database, run SQL queries, and read or modify data in a database.

 

Interfaces and Classes of JDBC API

  • DriverManager class − used to load a SQL driver to connect to database.
  • Connection interface − used to make a connection to the database using database connection string and credentials.
  • Statement interface − used to make a query to the database.
  • PreparedStatement interface − used for a query with placeholder values.
  • CallableStatement interface − used to called stored procedure or functions in database.
  • ResultSet interface − represents the query results obtained from the database.
  • ResultSetMetaData interface − represents the metadata of the result set.
  • BLOB class − represents binary data stored in BLOB format in database table.
  • CLOB class − represents text data like XML stored in database table

 

JDBC Drivers

The JDBC driver acts as a translator between Java/JDBC commands and the database's own communication protocol. JDBC drivers implement the defined interfaces in the JDBC API, for interacting with the database server.

 

Types of JDBC Drivers

There are 4 types of JDBC drivers:

Type

Name

Working

Type 1

JDBC-ODBC Bridge Driver

JDBC → ODBC → Database

Type 2

Native-API Driver

JDBC → Native Database API → Database

Type 3

Network Protocol Driver

JDBC → Middleware Server → Database

Type 4

Thin / Pure Java Driver

JDBC → Database directly

 


 

Type 1 – JDBC-ODBC Bridge Driver

The Type 1 JDBC driver acts as a bridge between JDBC and ODBC. It converts JDBC calls made by a Java program into ODBC calls, which are then sent to the database. Thus, the communication takes place through JDBC → ODBC → Database. It is an older type of driver and is no longer used in modern Java applications.

 

DBMS Driver type 1

 

Type 2 – Native-API Driver

The Type 2 JDBC driver converts JDBC calls into the native API calls of a particular database. It uses database-specific native libraries installed on the system to communicate with the database. Thus, the communication takes place through JDBC → Native API → Database. The driver contains both Java code and native code.

 

DBMS Driver type 2

 

Type 3 – Network Protocol Driver

The Type 3 JDBC driver uses a middleware server to communicate with the database. The Java application sends JDBC calls to the middleware server, which converts them into the appropriate database-specific requests. Thus, the communication takes place through JDBC → Middleware Server → Database. The middleware acts as an intermediate layer between the Java application and the database.

 

DBMS Driver type 3

 

Type 4 – Thin / Pure Java Driver

The Type 4 JDBC driver is a pure Java driver that communicates directly with the database using its network protocol. It converts JDBC calls into the database-specific protocol without requiring an intermediate middleware server. Thus, the communication takes place through JDBC → Type 4 Driver → Database. MySQL Connector/J is an example of a Type 4 JDBC driver.

 

DBMS Driver type 4

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu