Sunday, February 9, 2020

JDBC and JDBC Drivers


Introduction To JDBC (Java Database Connectivity)

Java JDBC stands for java database connectivity, JDBC is an API written in Java and enables the developers to connect their Java applications with the database management system. JDBC API is a collection of classes and interfaces required for database connectivity. JDBC specifies the calls to communicate with Database drivers. Database driver converts these JDBC calls into database commands, and let our application to make database operations. It means we can programmatically access the RDBMS.

java database connectivity
JDBC API


JDBC Drivers

JDBC Database Driver
Database Driver

A Database driver is a set of database commands written according to the JDBC Calls and enables the database to understand JDBC calls. A Database driver sits between the user and the RDBMS. Drivers act like an interface between the user and the RDBMS. There are four types of drivers for JDBC connectivity. Database drivers are either produced by database vendors themselves or by third parties as well. JDBC drivers are categorized into four types
  1. Type-1 JDBC -ODBC(Open Database Connectivity) Bridge Drivers
  2. Type-2 Native API Drivers 
  3. Type-3 Middleware or Network Drivers 
  4. Type-4 Thin driver or Database protocol drivers


Type -1(JDBC-ODBC Bridge Drivers)

JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls(ODBCare standard database connectivity specifications). These drivers are rarely used, generally during the development of a Database management system itself or some educational purposes. These types of drivers are not portable. 

Type-2(Native API Drivers)

Native API driver converts JDBC method calls into native calls of the database API. These drivers are used often due to a lack of portability. We also need to install database specific libraries for each and every machine making it difficult to update or reinstall the software.

Type-3(Network Protocol Drivers OR Middle-ware driver)

These drivers are expensive due to middle-ware or Application server used, However, these drivers are portable and these drivers are used for industrial applications.

Type-4(Thin Drivers or Database protocol drivers)

These drivers interact directly with the database, not require any native database library, that is why it is also known as Thin Driver. These drivers are portable and easy to use. These are the most commonly used drivers among all.  Almost all database vendors provide thin drivers for their products these days.

database drivers
Database Drivers

We can connect a Java Application to multiple databases. DriverManager class manages the list and track of all the drivers registered with the application. For creating a basic JDBC application with the SQLite database see this tutorial.

Video Tutorial