Updated April 10, 2023
Introduction to JDBC Driver
JDBC or Java Database Connectivity Driver is a software component that is analogous to ODBC drivers. The main purpose of JDBC is the ability to interact with Java applications with the database. The classes of JDBC are available in the packages javax.sql and java.sql. In addition to that, this helps in writing the applications that handle 3 programming activities such as:
- Connecting data sources like databases.
- Query sending and updating of statements present in the database.
- Retrieving as well as processing the responses obtained from the databases for the query sent.
Types of JDBC Driver
JDBC drivers are of four types. They are:
- JDBC-ODBC bridge driver
- Native-API driver
- Network Protocol driver
- Thin driver
1. JDBC-ODBC bridge driver
JDBC-ODBC bridge driver or Type-1 driver is used to connecting the ODBC driver to the database. As it is able to connect to any type of database, it is also known as Universal driver. Here, the method calls of JDBC have converted into method calls of ODBC using the JDBC-ODBC bridge driver. However, it is rarely used now because of the availability of a thin driver. Even though it was useful during the time databases to have ODBC drivers, Oracle does not recommend this now and advised the users that JDBC drivers offered by the vendors can be used instead of Type-1 drivers. In Java 8 also, JDBC-ODBC bridge drivers are not supported.
Structure:
Components:
- Client Machine with JDBC API, Java Application, JDBC-ODBC Bridge Driver, ODBC Driver, Vendor DB Library
- Database
Advantages:
- Independent of database connected
- Easy to use
- In-built with JDK
- Connection to the database can be done easily
Disadvantages:
- ODBC driver has to be installed on the machine of the client.
- Not a portable driver.
- Performance degradation as JDBC calls is converted to ODBC calls.
Application: Used in development as well as testing as it is not a deployment-level driver.
2. Native-API driver
Native-API driver or Type-2 driver is an implementation of a DB driver that uses databases’ client-side libraries. Here, the method calls of JDBC are converted into native calls of DB API. This driver is offered by the vendors and works similar to Type-1 drivers. Here, all Java applications are supported by this driver except the Java applets. Even though I also not a portable driver, it is secure as well as faster compared to the Type-1 driver.
Structure:
Components:
- Client Machine with JDBC API, Java Application, Native API Driver, Vendor DB Library
- Database
Advantages:
- Faster than JDBC-ODBC bridge driver.
- Secure data transfer compared to the type-1 driver.
- Upgraded performance compared to Type-1 driver.
Disadvantages:
- Platform dependent
- Except for applets, all java applications are supported by the driver.
- Client-side libraries do not exist in all databases.
- The vendor-client library, as well as vendor-specific driver, has to be installed in the machine of the client.
- Not a portable driver.
Application: Used in situations where the drivers of Type-3 and Type-4 are not available for the database you are using.
3. Network protocol driver
Network protocol driver or Type-3 driver is a driver that uses a middleware in order to convert method calls of JDBC into vendor-specific DB protocol. It is also known as a pure driver and follows a 3-tier communication approach in order to communicate with several databases. A standard network socket is needed by the clients of JDBC to communicate with the application server of middleware. The information or data obtained from the socket is then converted into to call format by the application server of middleware and forwards to the database. However, the supply of networks is needed on the client-side.
Structure:
Components:
- Client Machine with JDBC API, Java Application, Network protocol Driver
- Database
- Middleware in server-side
Advantages:
- The client-side library is not required as the server on the application can perform different functions such as logging, load balancing, auditing, etc.
- Any DB can be handled by a single driver if the middleware is present.
- Flexible
- Fully written in Java
- Secure
- Not specific to a vendor
Disadvantages:
- Network support is essential on the machine on the client-side.
- DB specific coding is required in the middle tier.
- Additional latency can occur as middleware is present.
- The maintenance cost is higher.
- The associated software is needed to work
Application: Used at the same time where the java applications access different types of databases
4. Thin driver
Type 4 driver or Thin driver is a driver that is purely Java-based that interacts directly with the database of the vendor using a socket connection. It is also known as Direct to Database Pure Java Driver and considered as the driver with the highest performance for the database. The thin driver is usually offered by the vendor. Since it is very flexible, special software is not needed to install on the client as well as server sides. Moreover, these drivers are possible to dynamically download. DB vendors commonly supply this type of driver due to their proprietary nature.
Structure:
Components:
- Client Machine with JDBC API, Java Application, Thin Driver
- Database
Advantages:
- Enhanced performance compared to another type of JDBC drivers
- Software need not be installed in the client as well as the server-side.
- Completely written in Java
- Flexible
- Portable drivers
- Native DB library is not required
- Middleware server is not required
- Also known as a native protocol driver
- Platform independent
- Proprietary nature
- Overhead does not occur during the conversion of JDBC calls in to ODBC calls or DB API calls.
- Facilitates debugging as Java Virtual Machine handles every aspect of the application to database connection.
Disadvantages:
- The driver is DB dependent
Application: Used at the time where the java applications access only one type of database such as IBM, Sybase, Oracle, etc.
Conclusion
JDBC drivers are used to connecting Java applications with databases. It gives a connection to the database and a protocol is implemented for query and result transferring between client and database. In this article, different types of JDBC drivers along with its pros, cons, structure, components, and application are discussed in detail.
Recommended Articles
This is a guide to JDBC Driver. Here we discuss an introduction to JDBC Driver, types with its structure, application, components, advantages, and disadvantages. You can also go through our other related articles to learn more –