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

  1. 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.
  2. This driver is platform-dependent because it uses ODBC calls which in turn depends on native libraries of OS  where the JVM is running.
  3. 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.
  4. 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.
  5. All java commands may not be supported due to ODBC dependency.
  6. Sun’s/Oracle’s JDBC-ODBC Bridge was removed in Java 8.

Drawbacks of using Type 1 Driver :

  1. 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).
  2. The ODBC driver needs to be installed on the client machine.
  3. Not suitable for applets, because the ODBC driver needs to be installed on the client.
  4. Portability is limited because, specific ODBC drivers may not always available on all platforms
  5. No support from JDK 1.8 (Java 8) onwards.

Type 2 driver – Native-API driver

 The JDBC type 2 driver, also known as the Native-API driver, is a database driver implementation that uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API.

  • 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)

  1. The JDBC type 3 driver, also known as the Pure Java driver for database middleware uses of a middle tier between the calling program and the database. The middle-tier (application server) converts JDBC calls directly or indirectly into a vendor-specific database protocol.
  2. This differs from the type 4 driver in that the protocol conversion logic resides not at the client, but in the middle-tier. Like type 4 drivers, the type 3 driver is written entirely in Java.
  3. Sends JDBC API calls to a middle-tier net server that translates the calls into the DBMS-specific network protocol.The translated calls are then sent to a particular DBMS.
  4. Follows a three-tier communication approach.
  5. Can interface to multiple databases – Not vendor specific.
  6. The JDBC Client driver written in java, communicates with a middleware-net-server using a database independent protocol, and then this net server translates this request into database commands for that database.

Type 4 driver – Database-Protocol driver (Pure Java driver)

  • The JDBC type 4 driver, also known as the Direct to Database Pure Java Driver, is a database driver implementation that converts JDBC calls directly into a vendor-specific database protocol.
  • Written completely in Java, type 4 drivers are thus platform independent. They install inside the Java Virtual Machine of the client. This provides better performance than the type 1 and type 2 drivers as it does not have the overhead of conversion of calls into ODBC or database API calls. Unlike the type 3 drivers, it does not need associated software to work.
  • As the database protocol is vendor specific, the JDBC client requires separate drivers, usually vendor supplied, to connect to different types of databases. This type includes, for example, the widely used Oracle thin 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.