Sunday, February 22, 2009

JDBC Drivers

The Java Database Connectivity (JDBC) is an application programming interface (API) that provides database independent connectivity between java applications and a wide range of databases that supports SQL, spreadsheets and flat files.

More details on this API can be found here.

The JDBC API uses JDBC Drivers to connect to databases. There are four types of drivers.

Type 1: JDBC-ODBC Bridge

This type of drivers are used when the database doesn't have a pure Java driver for connectivity. The bridge will translate the JDBC calls into ODBC (Open Database Connectivity) calls. This method is platform dependent as ODBC is a Microsoft Windows interface to SQL.

Pros:
  • Allows access to any database which has the ODBC driver installed.
Cons:
  • Degrades the performance as the JDBC calls goes through the bridge to the ODBC driver and then through the native database connectivity interface. The results comes back through the reverse process
  • The ODBC driver and the native database connectivity interface has to be installed on the client machine.
  • Cannot be used for web based applications as client side software is needed.
Eg: JDBC-ODBC Bridge by Sun

Type 2: Native-API/partly Java driver

This type of drivers communicates directly with the databases i.e they will convert the JDBC method calls into native calls for the database APIs. It is platform dependent as the native code has to be installed on the client machines.The driver is not written entirely in java as it communicates with the native code.

Pros:
  • Better Performance than type 1 drivers.
Cons:
  • Lower performance than type 3 and 4 drivers.
  • The native code (the vendor client library) has to be installed on the client side.
  • Cannot be used for web based applications as client side software is needed.
Eg: DB2 JDBC Type 2 Driver

Type 3: Net-protocol/all-Java driver

This type of drivers are written entirely in Java. The drivers follow a 3-tier architecture approach when connecting to a database. The JDBC calls are sent to the middleware server which directly or indirectly ( depending on the drivers used.) translates the JDBC requests to database specific calls through the native database connectivity interface. These drivers are platform independent.

Pros:
  • Vendor database libraries do not have to be present on client machines.
  • The middle ware server can provide middle ware services like caching (Query Results, Connections etc), Load balancing , System administration features such as logging and auditing.
Cons:
  • Database specific coding has to be done in the middle tier.
  • The Middle ware Server layer might result in a time bottle neck.
Eg: IDS Driver by IDS Software

Type 4: Native-protocol/all-Java driver

This type of drivers convert JDBC calls directly into the vendor-specific database protocols. The drivers are written purely in Java and is installed inside the JVM. As a result these drivers are platform independent.

Pros:
  • Provides better performance as there is no need for translating JDBC requests to intermediary forms or a middle ware server to service the requests.
  • Provides easier debugging as all aspects of the application to the database connection can be managed within the JVM.
Cons:
  • A seperate driver is needed for each database.
Eg: Oracle thin driver

No comments: