JDBC – J ava D ata B ase C onnectivity
JDBC is a Java API that enables java program to
execute SQL Statements.
The JDBC API can also be used to interact with
multiple data sources in a distributed ,
JDBC – ODBC Bridge (Type 1)
Translate JDBC call to ODBC calls and send them to the ODBC database.
It is a java Wrapper developed over ODBC API.
Advantages - 1. Easily available as part of JDK
2. Easy to install.
Disadvantages- 1. slower in performance.
2. Limited to functionality of ODBC driver.
3. Not Recommended for production environment.
Native-API partly Java Driver(Type2)
Written partly in java & partly in native code.
It uses a mixture of Java implementation and vendor-specific native API’s to
Uses native ‘c’ language lib calls for conversion.
Advantage – these offer better performance than jdbc-odbc bridge as layers are
less and it uses Native API which is database specific.
Disadvantage – not fully in java so portability issue , if database is changed than
native API must be changed as it is database specific.
Network Protocol All-Java Driver(type3)
This driver is Server based. So, the Vendor DB lib. Is not required for clients.
Uses DB independent Protocol to communicate DB-requests to a Server component.
Translates requests into DB-specific Protocol.
Advantages- 1. fully written in java , hence portable.
2. The net protocol can be designed to make the client JDBC driver very small
fast to load.
3. most efficient amongst all drivers.
Disadvantages- 1. requires another server application to be installed and maintained.
2. clients connect to DB servers via an intermediate server component that
as a gateway for multiple database servers.
Native Protocol All-Java Driver(type4)
•JDBC calls are directly converted to network protocol used by DBMS server
•It makes direct socket connections to the databases.
Advantages – 1.written in java only. So we can achieve platform independency.
2.number of translation layers are very less.
3.performance is good.
The user need a different driver for each database
There are seven standard steps in querying
1. Load the JDBC driver.
2. Define the connection URL.
3. Establish the connection.
4. Create a statement object.
5. Execute a query or update.
6. Process the results.
7. Close the connection.
Load the JDBC driver……………….
Only one time load in jdbc driver
How does one load a "class" into the Virtual
Use the static method Class.forName()
Define the connection URL………
Once a Driver is loaded, a connection can be made to the
The connection is defined by URL
• The URL has the following form:
A connection is obtained in the following manner:
• Connection conn =
Establish the connection…….
The Connection interface defines many methods
for managing and using a connection to the
• public Statement createStatement()
• public PreparedStatement
Create a statement object…….
The Statement interface .
• The most commonly used method is
• When an SQL statement is to be issued
against the database, a Statement object
must be created through the Connection
Execute a query or update……
The Statement interface defines two methods
for executing SQL against the database
public ResultSet executeQuery(String sql)
public int executeUpdate(String sql)
executeQuery returns a ResultSet
• All rows and columns which match the query are contained
within the ResultSet
• The developer navigates through the ResultSet and uses the
data as required.
executeUpdate returns the number of rows
changed by the update statement
• This is used for insert statements, update statements and
Close the connection………………..