Only institute to provide recording daily after class to students. Only institute you can practice whole day under faculty guidance. Only institute where test and mockup tests are taken regularly. Only institute provides all mobile nos of old students on website.

JDBC Tutorial

Describe What is JDBC?

JDBC is the java API which facilitates connectivity of java application to database.See below figure to more clear concept regarding JDBC.



Java By Kiran

Why JDBC introduced

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.
1. Application developers need to learn multiple API’s for multiple databases.
2. 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 Drivers

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

Type 1 or JDBC-ODBC Bridge 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.

Java By Kiran

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.

Type 2 or Native Driver

In this driver JDBC classes invokes function of vendor client library using JNI for each JDBC method call.

Java By Kiran

Advantage of Native driver
  • Better performance is obtaining as compare to Type-1 Driver.
  • ODBC Driver is not required.
Disadvantage of Native driver
  • Native Driver is needed to install each machine on which application is to execute.
  • The Vendor library needs to be installed.

Type 3 or Network Driver

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.
Java By Kiran

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.

Type 4 or Pure Java Native Driver

In this driver implementation classes of JDBC drivers interact to the database using database specific protocols and format.
Java By Kiran

Advantage 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.

JDBC interfaces

1.Connection
2.Statement
3.PreparedStatement
4.CallableStatement
5.ResultSet
6.ResultSetMetaData
7.DataBaseMetaData
8.SQLException

JDBC classes

1.DriverManager
2.SQLException
See below diagram how JDBC driver and JDBC API works.
Java By Kiran