Java Database Connectivity
For providing JDBC connectivity, you need to create a driver for your data system. The driver manager class is already available in JDK, no need to write a separate driver manager. There are 4 types of drivers. Out of which type 4 is the most adopted.
Java Based Database Drivers :
Type 1 driver : JDBC-ODBC bridge
- The JDBC type 1 driver is also known as the JDBC-ODBC bridge. This driver uses the ODBC driver to connect to the database. The driver converts JDBC method calls into ODBC function calls.
- This driver is platform-dependent because it uses ODBC calls which in turn depends on native libraries of OS where the JVM is running.
- There may arise some installation dependencies. For instance, ODBC must be installed on the computer having the driver and the database must support an ODBC driver.
- Any application using a type 1 driver is non-portable because of the tight binding of driver to platform. This technology isn’t suitable for a high-transaction environment.
- All java commands may not be supported due to ODBC dependency.
- Sun’s/Oracle’s JDBC-ODBC Bridge was removed in Java 8.
Drawbacks of using Type 1 Driver :
- Performance overhead since the calls have to go through the JDBC bridge to the ODBC driver, then to the native database connectivity interface (thus may be slower than other types of drivers).
- The ODBC driver needs to be installed on the client machine.
- Not suitable for applets, because the ODBC driver needs to be installed on the client.
- Portability is limited because, specific ODBC drivers may not always available on all platforms
- No support from JDK 1.8 (Java 8) onwards.
Type 2 driver – Native-API driver
- As there is no implementation of JDBC-ODBC bridge, it may be considerably faster than a Type 1 driver.
- The vendor client library needs to be installed on the client machine.
- This driver is platform dependent.
- This driver supports all Java applications except applets.
Type 3 driver – Network-Protocol driver (middleware driver)
Type 4 driver – Database-Protocol driver (Pure Java driver)
Benefits of using Type 4 Driver:
- Completely implemented in Java to achieve platform independence.
- These drivers don’t translate the requests into an intermediary format (such as ODBC).
- The client application connects directly to the database server. No translation or middleware layers are used, improving performance.
- The JVM can manage all aspects of the application-to-database connection; this can facilitate debugging.