
JDBC driver in Java is an API which is a set of classes and interfaces that helps the programmer to write programs for connection to database, retrieve data from database and perform many database related operations.
It is the essential feature for the project development which helps to communicate with any database through a java program. You can easily communicate with database even if you don’t know much about database commands, and if you are changing database then it will require few changes in java program.
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:
1. Type-1 driver or JDBC-ODBC bridge driver
This 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.
2. Type-2 driver or Native API driver
With the help of database library type-2 driver converts JDBC class into database specific calls, this driver communicates directly with the database server. It is directly understandable to the database.
So there must be some binary code in the client machine or that helps to communicate 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.
3. Type-3 driver or Network protocol driver
The type-3 driver is independent of database and it is pure java client library. It follows a three-tiered approach. It uses a middle-tier server, which translate the JDBC calls to database specific library and sends it to the database server. In other words, the request is passed through the network to server machine and then to 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,
4. Type-4 driver or Pure java driver (Thin driver)
The Type 4 driver is a pure Java library that translates JDBC calls directly into database-specific DBMS protocols. It helps the client to communicate directly with 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 for the built-in driver. The driver can pass any String to 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.