How many types of JDBC Drivers are there?

Java 8ProgrammingObject Oriented Programming

There are 4 types of JDBC drivers namely, Type-1, Type-2, Type-3 and, Type-4.

Type1

 It is the ODBC − JDBC bridge driver, it acts as a bridge between JDBC and, ODBC database connectivity mechanism. Using this you can access the databases which support only ODBC. Initially, it is used extensively, since most of the databases supported only ODBC.

Whenever Java application sends a request to the JDBC-ODBC bridge driver the request internally calls the ODBC equivalent function and the ODBC driver retrieves the result from the underlying database and sends it back to the JDBC-ODBC bridge driver.

Advantages of type1 driver

Following are the advantages of a type1 driver.

  • Using this single driver, you can access different DataSource.

  • You can access all the databases that support ODBC using this driver.

Disadvantages of type1 driver

Following are the disadvantages of a type1 driver.

  • The Java application’s (JDBC) request will be converted to ODBC and in turn, converted to Native Database calls.

  • When we use this driver Java application will be dependent on ODBC driver indirectly.

  • While using JDBC-ODBC driver you need to install ODBC binary code on every client.

Type2

Type 2 driver is known as a native API driver. This driver receives the calls from Java application and converts them into vendor specific native API calls. Here, we need to install The vendor-specific driver on the client machines.

If we change the Database, we have to change the native API, as it is specific to a database and they are mostly obsolete now, but you may realize some speed increase with a Type 2 driver because it eliminates ODBC's overhead.

Advantages of type2 driver

Following are the advantages of the type2 driver

  • This type of driver fastest among all the 4 types of drivers.

  • If we use this driver, we can also access the features provided by the database vendor.

Disadvantages of type2 driver

Following are the disadvantages of a type2 driver.

  • On the client machine, the Java Application calls are converted into vendor-specific database calls. Therefore, we must install native libraries on the client machine.

  • Since the native functions are executed on the client machine a small error in their execution can cause severe damage.

  • This driver causes more cost.

Type3

In a Type 3 driver, a three-tier approach is used to access databases. The JDBC clients use standard network sockets to communicate with a middleware application server. The socket information is then translated by the middleware application server into the call format required by the DBMS, and forwarded to the database server.

This kind of driver is extremely flexible, since it requires no code installed on the client, a single driver can actually provide access to multiple databases. You can think of the application server as a JDBC "proxy," meaning that it makes calls for the client application. As a result, you need some knowledge of the application server's configuration in order to effectively use this driver type.

Your application server might use a Type 1, 2, or 4 drivers to communicate with the database, understanding the nuances will prove helpful.

Advantages of type3 driver

Following are the advantages of the type3 driver.

  • This driver can be considered as pure Java driver.

  • Unlike type1 and type2 drivers, there is no need to install native libraries on the client machine.

  • You can access multiple databases using this driver.

  • Without changing the classes in the client side you can switch from one database to other.

Disadvantages of type3 driver

Following are the disadvantages of a type3 driver.

  • In case of increased network calls the communication will be slow.

  • When we use this driver Java application will be dependent on ODBC driver indirectly.

  • While using JDBC-ODBC driver you need to install ODBC binary code on every client.

  • This is the costlier compared to other drivers.

Type4

The Type 4 driver is the pure Java driver. It implements a database specific protocol to communicate with the database directly. This driver is provided by the vender itself, this is a flexible driver compared to other drivers.

Advantages of type4 driver

Following are the advantages of the type4 driver.

  • It is purely developed in Java and it is the platform independent driver.

  • Unlike type-1 driver, there is no need to install OCI, ODBC functions.

  • While using this driver there is no need for middleware server.

Disadvantages of type4 driver

Following are the disadvantages of a type4 driver.

  • Type-4 driver internally uses database specific proprietary protocol and it is database dependent. Therefore, whenever the database changed we need to change the driver accordingly.

raja
Published on 19-Mar-2019 15:51:58
Advertisements