Core java tutorial for beginners
A tutorial blog which explains different core concepts related to Java along with programming examples
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: JDBC. No Comments on Types of JDBC drivers in Java with examples
0
(0)

What is a JDBC driver?

A JDBC driver implements (provides code) the interfaces in the JDBC API. This enables a Java program to send SQL queries to a DBMS and receive back the results.

 

The java.sql package that comes along with JDK, contains various classes which specify the behavior. The actual code implementing that behavior is provided by the DBMS vendors. The DBMS vendors provide third-party drivers which should be installed for a Java program to communicate with the DBMS.

 

JDBC driver types

JDBC driver implementations vary because of the different types of operating systems and hardware platforms on which Java can run. Sun Microsystems has divided the JDBC driver implementations into four types.

 

Type 1 – JDBC-ODBC bridge driver

In a Type 1 driver, the JDBC-ODBC bridge driver is used to communicate with the ODBC driver installed on each client machine. For using ODBC, we need to configure a Data Source Name (DSN) that represents the target database.


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


 

ODBC drivers are now-a-days obsolete and were the only choice when Java first came out. At that time database vendors only supported ODBC drivers. Now, this type of driver is only recommended for experimental purpose or when there is no other alternative.

 

The JDBC-ODBC bridge that was released along with Java 1.2 is a good example of this type of driver. Type 1 driver can be illustrated as shown below.

JDBC type 1 driver JDBC ODBC bridge driver

 

Type 2 – JDBC-Native API driver

In a type 2 driver, the JDBC API calls are converted into native C/C++ calls which are unique to the database. These drivers are made available by the DBMS vendors. This vendor-specific driver needs to be installed on every client machine.

 

This type of driver is obsolete now, but you can see a raise in the performance of application as there is no intermediate ODBC driver. The Oracle Call Interface (OCI) is an example of type 2 driver. Type 2 driver can be illustrated as shown below.

 

JDBC type 2 driver Native API driver

 

Type 3 – JDBC-Net pure Java driver

The type 3 driver follows the three-tier architecture. The JDBC clients use standard network socket communication to communicate with middleware which is generally an application server. The socket communication received is converted into database specific instructions by the middleware.

 

The type 3 driver is extremely flexible as it does not require software to be installed on each client machine. Further, a single driver enables to communicate with multiple databases. The only extra thing needed is, technical knowledge related to configuring an application server.

 

The application server can use either type 1, type 2 or type 4 driver to communicate with the database. Type 3 driver can be illustrated as shown below.

 

JDBC type 3 driver JDBC Net pure driver

 

Type 4 – Pure java driver

In type 4 driver, the pure java-based driver directly communicates with the database through socket connection. This driver is the highest performance driver and is typically provided by the database vendor.

 

This driver is extremely flexible as no special type of software needs to be installed on both client and the server. Further, the driver files can be downloaded automatically. MYSQL’s Connector/J driver is an example of type 4 driver. Type 4 driver can be illustrated as shown below.

 

JDBC type 4 driver Pure Java driver

 

When to use which type of JDBC driver?

If the Java application is trying to access only one type of database like Oracle, MYSQL, Sybase, etc., type 4 driver is preferable.

 

If the Java application is trying to access multiple types of databases at the same time, type 3 driver is preferable.

 

When type 3 or type 4 drivers are not available, type 2 driver is more preferable as it offers better performance.

 

Finally, if all other types of drivers are not available, type 1 driver can be used for connecting with the database.

 

For more information on JDBC, refer the following links:

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.

Leave a Reply

Your email address will not be published. Required fields are marked *