Java JDBC - JDBC Drivers

JDBC Drivers helps in interacting with databases. JDBC driver manager makes sure that correct driver is used to access each data source. There are 4 types of JDBC drivers :

  1. Type 1 : JDBC-ODBC Bridge Driver
  2. Type 2 : Native API Driver (partially java driver)
  3. Type 3 : Network Protocol or Net Pure Driver (fully java driver)
  4. Type 4 : Thin Driver (100% pure java driver)
Now we will discuss all of these 4 types in detail :

Type 1 : JDBC-ODBC Bridge Driver

This driver uses ODBC driver installed on client machine to make connection to data source. In order to use this driver, we need to configure Data Source Name (DSN) on our machines which represents target database. This is the oldest driver we have and it is not much in use. Moreover, support for this driver has been stopped from Java 8.

JDBC Type 1 Driver

There are few disadvantages of using this driver :

  1. Performance of the applications gets degraded as the JDBC calls gets converted into ODBC class for executing SQL statements.
  2. ODBC driver needs to be installed on client machine.
  3. Support for this driver is ended in Java 8


Type 2 : Native API Driver

When we use this driver JDBC calls are converted into native C/C++ calls. This driver is not entirely written in Java. These drivers are used in same manner as JDBC-ODBC Bridge. These drivers are vendor specific and needs to be installed on each client machine. If we change the database then we need to change the native API library as well.

Type 2 JDBC Driver


Performance with these drivers are upgraded as compared to JDBC-ODBC Bridge. There are some disadvantages as well :

  1. These needs to be installed on each client machine.
  2. In addition to drivers vendor specific API also needs to be installed on client machine. 

Type 3 : Network Protocol or Net Pure Driver

These drivers are purely written in Java language. These drivers used a 3-tier architecture for communication with databases. Most of DB related tasks are handled by a middleware server which converts JDBC calls directly or indirectly into vendor specific database protocol.
These drivers are very flexible as compared to previous drivers because it does not require any code to be installed on client machine.

Type 3 JDBC Driver

.

Type 4 : Thin Driver (100% Pure Java Driver)

This is a pure Java-based driver, which communicates directly with vendor's database through socket connection. Performance wise this is the best driver to choose. This driver doesn't require any native database library for interaction with database. Moreover, we don't need to install any kind of special software on client or server machine.

Type 4 JDBC Driver


Which driver to should be used and when?

If we are accessing one type of database, such as Oracle, MySQL, Sybase etc. then we should use Type 4 driver.
If our Java Application is accessing multiple types of databases at same time then, we should use Type 3 driver.
If neither Type 4 nor Type 3 is available for the database used by our application then we should go for Type 2 driver.
We should not use Type 1 for deployment purpose, it should be only used for development and testing purposes only.

Share:

Related Posts:

No comments:

Post a Comment

Popular Posts

Recent Posts

Followers

Total Pageviews

5,030