Thursday, 24 July 2014

JDBC Driver Types

Java Database Connection is a set of classes that help us to connect and communicate with database.
Every vendor of database add the code in classes that implements JDBC interface and you don't need to re-invent the wheel from scratch; you have just call the public method and every particular method of driver know how to react and behave.

Let's consider 
createConnection(); here is the method and every jdbc vendor driver know how to create a connection with database.Oracle vendor driver know how to create connection with oracle database and similarly Microsoft vendor Driver know how to create connection with the database etc.

Note :You have use JDBC interface from java.sql classes, so the type of driver will not have any logic impact in your code, it will only have run time / deployment impact.




Type of JDBC Driver
  
There are 4 JDBC driver tpes/level
Type 1: JDBC-ODBC Bridge driver (Bridge)

Type 2: Native-API/partly Java driver (Native)


Type 3: All Java/Net-protocol driver (Middle ware)


Type 4: All Java/Native-protocol driver (Pure)



Type 1
ODBC (Open database Connectivity) is actually Microsoft protocol to chat fetching and updating  the data of database.JDBC -ODBC bridge driver which really means an ODBC connection wrapped in JDBC clothing.
 In this implemented class in Java makes calls to the code written in Microsoft languages (native), which speaks directly to the database.
 In this you first create DSN (Domain Source Name) in the client machine then it's registered with the JDBC.
This is very first and slow driver type of JDBC relatively than other driver type;because translation or conversion and many step require to reach database data.


 
Type 2 Driver
A type 2 JDBC driver is like a type 1 driver, except the ODBC part is replaced with a native code part instead.Actually the type-2 drivers  use a Java (JDBC) API to call native api and native code work with the database.





Type 3 Driver

Type 3 drivers basically proxy (or relay) the request to another network resource. That typically incurs an extra network hit, but again, that doesn't say much about actual performance.follows a three-tiered approach whereby the JDBC database requests are passed through the network to the middle-tier server. The middle-tier server then translates the request (directly or indirectly) to the database-specific native-connectivity interface to further the request to the database server.

Type 4 Driver
The Type 4 uses Java  libraries to communicate directly with the database server.This driver is fastest among all drivers.The Java program connects directly to the database if type  driver used.




No comments:

Post a Comment