Core Java Tutorials


Introduction

Java Hello World

Java Compilation

JDK New Features

JVM Architecture

Java OOPs Concepts

Java Package

Array

Exception Handling

String

Immutable Class

File Handling

Serialization

MultiThreading

Volatile

Concurrent Package

Collection

Collection Internal

Generics

Cloning

Reflection In Java

Annotation

Class Loader

Java Inner classes

Garbage Collector

JDBC

References In Java

Heap Dump & Thread Dump

/java/jdbc-driversPrevious             Next

JDBC Drivers

To connect with individual databases, JDBC (the Java Database Connectivity API) requires drivers for each database. The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database.

Types of JDBD Drivers

JDBC-ODBC bridge driver
Native-API driver
Network-Protocol driver
Pure Java driver or thin driver.

JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver, also known as the type 1 driver, 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.Type 1 drivers are (were) mostly intended to be used in the beginning, when there were no type 4 drivers (all Java drivers).


Advantages

Allow easy connectivity to all database supported by the ODBC Driver.

Disadvantages

Slow execution time since the calls have to go through the JDBC bridge to the ODBC driver, then to the native db connectivity interface
The ODBC driver needs to be installed on the client machine.
Uses Java Native Interface(JNI) to make ODBC call.

Native-API driver

The Native-API driver, also known as the type 2 driver, is a database driver implementation that uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API.These native client API are usually written in C and C++.


Advantages

faster as compared to Type-1 Driver, because there is no implementation of JDBC-ODBC bridge

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.
This driver is platform dependent.

Network-Protocol driver

The JDBC type 3 driver, also known as the Pure Java driver for database middlewares,its 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,The type 3 driver is server-based, so there is no need for any vendor database library to be present on client machines. Further, there are many opportunities to optimize portability, performance, and scalability. Moreover, the net protocol can be designed to make the client JDBC driver very small and fast to load.

Advantages

database independent, there is no need for the database vendor library on the client.
its 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.
Network support is required on client machine.
The middleware layer added may result in additional latency, but is typically overcome by using better middleware services.

Pure Java driver or thin driver.

This database driver implementation that converts JDBC calls directly into a vendor-specific database protocol, this driver Written completely in Java,type 4 drivers are thus platform independent. They install inside the Java Virtual Machine of the client. This provides better performance than the type 1 and type 2 drivers as it does not have the overhead of conversion of calls into ODBC or database API calls. Unlike the type 3 drivers, it does not need associated software to work,As the database protocol is vendor specific, the JDBC client requires separate drivers, usually vendor supplied, to connect to different types of databases.

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.

Disadvantages

Drivers are database dependent, as different database vendors use widely different (and usually proprietary) network protocols.
With type 4 drivers, the user needs a different driver for each database.



/java/jdbc-driversPrevious             Next