2. Introduction
•It is an API (Application Programming Interface)
•Used to connect JAVA application with database
•Interact with different types of databases like,
MS Access, MySQL, Oracle, SQL Server,
PostgreSQL, Sybase
07/01/16 2
3. JDBC Driver
•Type-1 Driver ( JDBC-ODBC Bridge)
•Type-2 Driver (Native-API Partly Java Driver / Partly Java)
•Type-3 Driver (Network Protocol Driver / Pure Java to Middleware)
•Type-4 Driver (Thin Driver / Pure Java Direct to Database)
07/01/16 3
4. Type-1 Driver ( JDBC-ODBC Bridge)
•Act as a bridge between JDBC
and other database connectivity
mechanism (ODBC)
•Converts JDBC calls into ODBC
calls and redirects the request
to ODBC driver
•Sun provides a JDBC-ODBC
Bridge Driver
07/01/16 4
5. Type-1 Driver ( JDBC-ODBC Bridge) cont…
•Advantages
Easy to use
Allow easy connectivity to all database supported by the ODBC
Driver
•Disadvantages
Slow execution time
Dependent on ODBC Driver
Uses Java JNI (Native Interface) to make ODBC call
07/01/16 5
6. Type-2 Driver (Native-API Partly Java Driver /
Partly Java)
•Converts JDBC calls into calls to the
client
API for that database
•Client
JDBC Driver
Vendor Client DB Library
DB
07/01/16 6
7. Type-2 Driver (Native-API Partly Java Driver /
Partly Java) cont…
•Advantages
Better performance than Type-1 because no JDBC to ODBC
translation is needed.
•Disadvantages
Vendor client library needs to be installed on the client machine.
Can not be used in web-based application due the client side s/w
needed.
Not all database have a client side library.
07/01/16 7
8. Type-3 Driver (Network Protocol Driver / Pure
Java to Middleware)
•Follow three tier communication
approach
•Can interface to multiple databases
•Client
JDBC Driver
Middleware-Net Server
Any Database
07/01/16 8
9. Type-3 Driver (Network Protocol Driver / Pure
Java to Middleware) cont…
•Advantages
Does not require any native library to be installed.
Database Independency
Provide facility to switch over from one database to another
database
•Disadvantages
Slow due to increase number of network call
07/01/16 9
10. Type-4 Driver (Thin Driver / Pure Java Direct
to Database)
•Interact directly with database
•Does not require any native
database
library
•Called pure Java Driver
•Also known as Thin Driver
07/01/16 10
11. Type-4 Driver (Thin Driver / Pure Java Direct
to Database)
•Advantages
Does not require any native library
Does not require any Middleware server
Better Performance than other driver
•Disadvantages
Slow due to increase number of n/w call
At client side, a separate driver is needed for each database
07/01/16 11
13. Connection Interface
Method Description
void close() This method frees the connection object’s database and other JDBC
resources
void commit() This method makes all the changes made since the last commit or
rollback. It throws SQLException
boolean isClosed() This method returns “true” if the connection is close else returns
“false”
void rollback() This method undoes all changes made to the database
Statement createStatement() This method creates a Statement object for sending SQL statements
to the database. throws SQLException
CallableStatement
prepareCall(String s)
This method creates a CallableStatement object for calling stored
procedures. It throws SQLException
PreparedStatement
prepareStatement(String s)
This method creates a PreparedStatement object for sending SQL
statements with or without IN parameter. It throws SQLException.
07/01/16 13
14. Statement Interface
Method Description
void close() this method releases the statement object’s database and JDBC
resources
boolean execute(String s) This method executes the SQL statement specified by s.
ResultSet executeQuery(String s) This method executes the SQL statement specified by s and returns
the ResultSet object
int executeUpdate(String s) This method executes the SQL statement specified by s. These
statements may be INSERT, UPDATE or DELETE
int getMaxRows() This method returns the maximum number of rows that are
generated by the executeQuery() method
ResultSet getResultSet() This method retrieves the ResultSet generated by the execute()
method
07/01/16 14