JDBC is the java API which facilitates connectivity of java application to database. See below figure to more clear concept regarding JDBC.
A database vendor provide interface for human user as well as for application in their RDBMS package.
Interface of an application represents a set of functions which are defines by the database vendors in the native technology of the database.
Application developers need to learn multiple API’s for multiple databases.
Application need to be modified each time RDBMS package is change.
Solution of these problems is provided by ODBC. ODBC(open database connectivity) is a set of c functions prototype, implementation of these is provided by database vendors.
ODBC functions are written in c language. Hence developers need to invoke c functions for different database packages. To facilitate interaction of java application to databases in JAVA, Sun Micro System provide JDBC(Java Data Base Connectivity).
JDBC Driver is implementation of JDBC API by different vendors in different ways.Depending upon vendors implementations we are have 4 types of JDBC drivers.
Type 1 or JDBC-ODBC Bridge Driver
Type 2 or Native Driver
Type 3 or Network Driver
Type 4 or Pure Java Native Driver
In Type-1 JDBC driver, driver classes provided by vendors which is written in c language invokes ODBC functions using JNI(Java Native Interface). It converts JDBC methods call to ODBC functions call and then Native Driver execute queries from database.
Advantage of JDBC-ODBC driver:
Advantage of this driver is that single driver implementation can be used with all databases.
Disadvantage of JDBC-ODBC driver:
Measure disadvantage is performance degradation. Each database operation required multiple calls and conversion which degrades performance. ODBC driver need to be installed on each machine where application is to be executed.
In this driver JDBC classes invokes function of vendor client library using JNI for each JDBC method call.
Advantages of Native driver:
Better performance is obtaining as compare to Type-1 Driver.
ODBC Driver is not required.
Disadvantages of Native driver:
Native Driver is needed to install each machine on which application is to execute.
The Vendor library needs to be installed.
In this driver implementation classes of JBDC interface invokes function of native drivers over the network using the standard network protocols such as TCP/IP.
Advantage of Network driver:
Native driver need to be installed on a single machine on the network.
Disadvantage of Network driver:
Performance is degraded because of additional network overhead.
In this driver implementation classes of JDBC drivers interact to the database using database specific protocols and format.
Advantages of Pure Java Native driver:
Better performance is obtaining as compare to other drivers.
ODBC and native drivers is not required.
Disadvantage of Pure Java Native driver:
For each database different implementation is required.
Connection
Statement
PreparedStatement
CallableStatement
ResultSet
ResultSetMetaData
DataBaseMetaData
SQLException
DriverManager
SQLException
See below diagram how JDBC driver and JDBC API works: