Different Types of JDBC Drivers in Java - Quick Overview (original) (raw)

How many types of JDBC drivers in Java is a classical JDBC interview question, though I have not seen this question recently it was very popular during the last decade and still asked mostly on Junior programmer level interviews. There are mainly 4 types of JDBC drivers in Java, those are referred to as type 1 to type 4 jdbc drivers. I agree it's easy to remember them by type rather than with their actual name, Which I have yet to get in-memory except for plain old JDBC-ODBC bridge driver.

By the way here are their full names :

Type 1 JDBC Driver is called JDBC-ODBC Bridge driver (bridge driver)

Type 2 JDBC Driver is referred to as Native-API/partly Java driver (the native driver)

Type 3 JDBC Driver is called AllJava/Net-protocol driver (middleware driver)

Type 4 JDBC Driver is called All Java/Native-protocol driver (Pure java driver)

This JDBC tutorial is in continuation of my earlier tutorials in JDBC like How to connect to Oracle database using JDBC and 4 tips to improve performance of JDBC applications. If you are new here and haven't read them already, Its worth looking.

Anyway out of all those 4 types, the JDBC-ODBC Bridge driver is most common for connecting SQL Server, MS Access and mostly on training and development. here are a quick review of all these four types of JDBC drivers. Also there has been some speculation of type 5 JDBC driver, I have to yet to see it.

JDBC ODBC Bridge Driver or Type 1 JDBC driver

types of JDBC drivers in JavaIn case of JDBC ODBC bridge driver all JDBC calls doesn't directly goes to database instead they go via ODBC driver. JDBC-ODBC driver translates JDBC calls into ODBC calls and sends them to the ODBC driver for passing to database. Since type 1 driver act as a bridge between JDBC and ODBC and that's why its called JDBC-ODBC bridge driver.

This driver is not fast and good for production use mainly because of several layer of translation on back and fourth database traffic but it has an advantage in terms of of availability and can be your last choice.

1. Native-API/partly Java driver or Type 2 JDBC driver

This is also called type 2 driver and it's slightly better than type 1 JDBC driver. type 2 JDBC driver converts JDBC calls into database calls by using native API provided by the database. This driver is database-specific so once you switch from one database to another you need to change type 2 JDBC driver. performance is better than the JDBC-ODBC bridge driver since the communication layer is reduced. type 2 JDBC driver requires database native library to be available on the client but it poses several versions and compatibility issues. This was liked by Database vendors though because they can reuse there existing native libraries.

2. All Java/Net-protocol driver or Type 3 JDBC driver

both type 1 and type 2 JDBC drivers were not written in Java so there was need for pure Java JDBC driver to resolve portability issues. type 3 JDBC driver comes with pure java implementation (that's why All Java word ) but it uses 3 tier architecture where you have a Java client and Java Server which talk with Net protocol and Server speaking to the database. type 3 JDBC driver never get popular among database vendors as it was costly for them to rewrite their existing native database library which was mainly on C and C++.

3. All Java/Native-protocol driver or Type 4 JDBC driver

type 4 JDBC driver is most popular among all four types of JDBC drivers. it has not only been implemented in Java but also incorporates all database call in a single driver. It was pretty easy to use and deploy as well just include driver's jar in the classpath and you are ready.

It also removes 3 tier architecture of type 3 JDBC driver which makes it faster than type 3. Major development happens on type 4 JDBC driver when databases upgrade themselves, though some of them still upgrade native database library or type 2 driver.

That's all on a quick overview of different types of JDBC drivers in Java. JDBC drivers have evolved from JDBC ODBC bridge driver to type 4 JDBC driver, which is clean and portable. There has been some buzz around JDBC driver 5 on the Java community which may include some advanced functionality. let us know if you come across some news on JDBC 5 driver.