
The Java JDBC driver is an API, or collection of classes and interfaces, that enables programmers to connect to databases, retrieve data from them, and carry out a variety of other database-related tasks.
It is a feature that is essential for the project development since it enables Java program to communicate with any database. Even if you are unfamiliar with database commands, you can still connect with the database. However, updating the database requires modifications to the Java code.
And the most important thing about JDBC driver is that it provides better maintainability of the code on different platforms.
Full form of JDBC is Java Database Connectivity.
Each driver has its own advantages and disadvantages which we will discuss in this article.
Table of Contents
Types of JDBC driver in Java
There are four types of JDBC drivers which are as follows:
Type-1 driver or JDBC-ODBC bridge driver
JDBC-ODBC bridge driver or Type-1 driver depends on the ODBC driver, it receives any JDBC calls and sends them to the ODBC driver, and then ODBC communicates with the database library when it understands it. In other words, to communicate with database it converts the JDBC calls to ODBC function calls.
Advantages of JDBC-ODBC bridge driver
- It is database dependent driver.
- Very easy to use.
- It allows access to almost all the database.
Disadvantages of JDBC-ODBC bridge driver
- Performance of this driver is not much good.
- We need to install on client machine.
Type-2 driver or Native API driver
The type-2 driver, which communicates directly with the database server, helps the database library in converting JDBC classes into database-specific calls. This makes sense when applied to the database directly.
Therefore, the client computer must have some binary code that facilitates communication with the server.
Advantages of Native API Driver
- It offers better performance than JDBC-ODBC bridge driver.
- Type-2 does not require an ODBC driver.
Disadvantages of Native API Driver
- It is vender specific driver.
- You need to load library on each client machine.
- You cannot use type-2 driver for the internet.
- It is not a portable driver because it is not written in Java.
Type-3 driver or Network protocol driver
The Type-3 driver is independent of the database and is a pure Java client library. It follows a three-tiered approach. It uses a middle tier server, which translates the JDBC calls into a database specific library and sends it to the database server. In other words, the request is sent through the network to the server machine and then to the database server.
Advantages of Network protocol driver
- It is portable driver because it is written in java.
- There is no requirement of vendor specific library.
Disadvantages of Network protocol driver
- Client machine required network support.
- We need to change middle tier code if we change the database.
- Maintenance is very costly,
Type-4 driver or Pure java driver (Thin driver)
Type 4 Driver is a pure Java library that directly translates JDBC calls into database-specific DBMS protocols. It helps the client to communicate directly with the database server.
Mostly, we use type-4 driver on the internet.
Advantages of Thin driver
- It provides better performance than all other drivers.
- It is portable because it is completely written in Java.
- There is no need to install any library on the client system.
Disadvantages of Thin driver
- The main disadvantage of this driver is that it is database dependent. We need database specific driver. For example, if we are using Oracle then we have to use Oracle driver, if we are using MySql database then we have to use MySql driver.
Why didn’t Sun adopt the ODBC model?
- ODBC is hard to learn and it has some commands with lots of complex options.
- ODBC relies on the use of void* pointers.
- It uses C features that are not inherent in the Java programming language, so it can be difficult for Java programmers.
- An ODBC-based solution is less safe and harder to deploy than a pure Java solution.
Ultimate goal of the JDBC
The JDBC specification actually allows you to pass any string to the underlying driver. The driver can pass any string to the database.
Programmers can write applications in the Java programming language to access any database, using standard SQL as well as using extensions to SQL.
In conclusion, if you got the idea about the JDBC driver then your next step should be the java connectivity with database. Hope you liked the article of JDBC driver in Java. Feel free to contact on geekcer.code@gmail.com or you can write a comment if you have any doubt and query.