A Java application that wishes to communicate with any specific database uses JDBC Application Programming Interface(API).
JDBC API is set of methods and classes using which a Java application
communicates with a JDBC driver, which in turn communicates directly with a specific database.
For example- A Java Application wishing to stores its data with MariaDB database, should use JDBC
API, which will directly act as an interface between Java application and MariaDB database. This JDBC API will communicate with a vendor specific
- JDBC MariaDB Driver, which will directly communicate with MariaDB dabatase.
Accessing this specific JDBC driver using JDBC API allows this Java application to store, query or retrieve its data in MariaDB database.
This JDBC API interacts with a database vendor specific JDBC driver, which communicates directly with the database.
Types of JDBC drivers
There are over 200 different kinds of JDBC drivers available which are broadly categorized into four types.
Let's know a little bit about each of these four types of JDBC Drivers.
JDBC-ODBC Bridge Driver / Type-1 Driver
Some databases provide an ODBC driver to allow applications to connect to their databases, where ODBC stands for Open Database Connectivity.
A Java Application wishing to communicate with a database that has an ODBC driver, will use JDBC API to communicate with a JDBC-ODBC Bridge Driver.
This JDBC-ODBC Bridge Driver will directly communicate with a particular ODBC driver, which further directly communicates with its specific database.
Advantage of JDBC-ODBC Bridge Driver
Using the JDBC-ODBC Bridge Driver, a Java application can easily communicate with a database that has provided an ODBC driver.
Disdvantage of JDBC-ODBC Bridge Driver
Java application is dependent on ODBC driver for communicating with database.
Native - API Partly Java Driver / Type-2 Driver
Some database vendors only provide native APIs to access their database. These native APIs are written in C/C++ or Assembly Language. When a Java application
wants to communicate or stores its data in a database that only provides Native APIs, then it must use Native - API Partly Java Driver.
How a Java application connects to a database through a Native - API Partly Java Driver .
A Java application running at the client-side using JDBC API makes JDBC calls.
These JDBC calls are to translated to database specific native calls using Native - API Partly Java Driver.
These native calls are passed over to database specific native library(API), also loaded on the client-side.
Finally, this native library further communicates with the database.
Note: An example of a database using a Native - API Parly Java Driver is WebLogic - OCI Driver.
Advantage of JDBC-ODBC Bridge Driver
In the absence of JDBC-ODBC bridge, this driver is faster than Type-1 driver.
Disadvantage of JDBC-ODBC Bridge Driver
Using this driver requires database specific native Library APIs to be stored on the client-side because it is used to translate JDBC calls to database specific calls to communicate
with a database.
Advertisement
Pure Java Driver for Database Middleware / Type-3 Driver
This type of JDBC driver converts the JDBC calls made by a Java Application at a client-side to a Middleware Server specific network calls.
At Middleware Server, the server specific calls are received and converted to a database specific calls and the specific database is communicated.
Note : Network calls made by Type-3 driver from client-side to middleware server are database independent,
hence a single JDBC Type-3 driver at client-side can be used to access multiple databases.
This driver is fully written in Java and it is mainly used for connecting applets with databases. An example of a Pure Java Driver for Database Middleware is Weblogic RMI Driver.
Advantage of JDBC-ODBC Bridge Driver
This driver doesn't require database specific native library to be stored on the client-side machine.
A single JDBC driver can be used to access multiple databases without changing JDBC driver at client-side.
Disadvantage of JDBC-ODBC Bridge Driver
Slow performance because of a number of network calls to an intermediate middleware server.
Direct-to-Database Pure Java driver / Type-4 Driver
This type of JDBC driver communicates directly with a database, without requiring any native database libraries or middleware server in between.
To communicate with a database,
the JDBC calls made by a Java application(using JDBC API) are translated by Direct-to-database pure Java driver to database specific calls.
Note : An example of Direct-to-database pure Java driver is Oracle provided - thin driver.
Advantage of direct-to-database pure Java driver
This driver is lightweight as it is directly connected to a database without requiring any native database libraries on the client-side,
nor does it require any middleware server
Due to its lightweight, this driver can be used both for client-side or for server-side Java enterprise applications.