JDBC Drivers Types

JDBC driver implementations vary because of the wide variety of operating systems and hardware platforms in which Java operates. Sun has divided the implementation types into four categories, Types 1, 2, 3, and 4, which is explained below:

Type 1: JDBC-ODBC Bridge Driver:

The JDBC type 1 driver, also known as the JDBC-ODBC bridge, is a database driver implementation that employs the ODBC driver to connect to the database. The driver converts JDBC method calls into ODBC function calls. 
ODBC:Open Database Connectivity is a standard C programming language middleware API for accessing database management systems (DBMS).
When Java first came out, this was a useful driver because most databases only supported ODBC access but now this type of driver is recommended only for experimental use or when no other alternative is available.

Fig1:Type1 Driver
Advantages
Almost any database for which ODBC driver is installed, can be accessed.

Disadvantages

  • Performance overhead since the calls have to go through the jdbc Overhead bridge to the ODBC driver, then to the native db connectivity interface (thus may be slower than other types of drivers).
  • The ODBC driver needs to be installed on the client machine.
  • It is platform dependent
Example:
The JDBC-ODBC bridge that comes with JDK 1.2 is a good example of this kind of driver.


Type 2: JDBC-Native API:

The JDBC type 2 driver, also known as the Native-API driver,
In a Type 2 driver, JDBC API calls are converted into native C/C++ API calls which are unique to the database. These drivers typically provided by the database vendors and used in the same manner as the JDBC-ODBC Bridge, the vendor-specific driver must be installed on each client machine.
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.
Type 2:Driver

Advantages

  • As there is no implementation of jdbc-odbc bridge, its considerably faster than a type 1 driver.

Disadvantages

  • The vendor client library needs to be installed on the client machine.
  • Not all databases have a client side library
  • This driver is platform dependent
Example:
The Oracle Call Interface (OCI) driver is an example of a Type 2 driver.

Type 3: JDBC-Net pure Java:

The JDBC type 3 driver, also known as the Pure Java Driver for Database Middleware. In a Type 3 driver, a three-tier approach is used to accessing databases.  The JDBC clients use standard network sockets (TCP/IP) to communicate with an middleware application server (hence known as network protocol driver). 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.The same driver can be used for connecting to multiple databases. It depends on the number of databases the middleware has been configured to support. Also, making use of the middleware provides additional advantages of security and firewall access.

Advantages

Type3:Driver
  • Since the communication between client and the middleware server is database independent, there is no need for the database vendor library on the client. The client need not be changed for a new database.
  • The middleware server (which can be a full fledged J2EE Application server) can provide typical middleware services like caching (of connections, query results, etc.), load balancing, logging, and auditing.
  • A single driver can handle any database, provided the middleware supports it.

Disadvantages

  • Requires database-specific coding to be done in the middle tier.
  • The middleware layer added may result in additional latency, but is typically overcome by using better middleware services. 
Example
  • IDA Server

Type 4 Driver - Native-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 (hence also known as Native-Protocol driver).This is the highest performance driver available for the database and is usually provided by the vendor itself.This kind of driver is extremely flexible, you don't need to install special software on the client or server. Further, these drivers can be downloaded dynamically.
Type4:Driver

Advantages

  • 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.
  • Provides a way to manage copies of the database for each user.

Disadvantages

  • Drivers are database dependent, as different database vendors use wildly different (and usually proprietary) network protocol

Example:

The widely used Oracle thin driver



Differences Between JDBC Drivers:

Driver Type
Driver Name
Function
Pure Java
Platform dependent
Type I
JDBC-ODBC Bridge
JDBC method calls into ODBC function calls
NO
YES
Type II
Native -API
JDBC method calls into native calls of Database API
NO
YES
Type III
Network-Protocol Driver
Middle tier converts JDBC calls directly or indirectly into vendor specific database protocol
YES
NO
Type IV
Native Protocol Driver
JDBC calls directly into vendor specific database Protocol
YES
NO

Which Driver should be used?
  • If you are accessing one type of database, such as Oracle, Sybase, or IBM, the preferred driver type is 4.
  • If your Java application is accessing multiple types of databases at the same time, type 3 is the preferred driver.
  • Type 2 drivers are useful in situations where a type 3 or type 4 driver is not available yet for your database.
  • The type 1 driver is not considered a deployment-level driver and is typically used for development and testing purposes only.
                          
                  Prev                                         Next

Comments

Popular posts from this blog

Servlet Advantages and Disadvantages

The Deployment Descriptor: web.xml

Session Management