



















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




















An Introduction
JDBC
docsity.com
o Java Database Connectivity
Concepts JDBC API Data Base Connectivity using Java Important Features of JDBC API
docsity.com
o Role of Driver
JDBC API talks with vendor specific driver Driver converts JDBC API calls to vendor specific Database API calls
o Merits and Demerits Applications using JDBC API have no access to vendor specific Database API but to driver only The performance is reduced The same application can be used with another implementation of the same database for any other vendor for which a driver is available
docsity.com
o Database drivers are classified into four types based on the nature of the driver provided Bridges. Convert from JDBC to another standard for example ODBC. That standard then converts into the vendor specific API.
Part Java part Native Driver contains some Java code and some Native code
Intermediate Server JDBC talks directly to a separate server which then converts from JDBC to native API (great for intranets)
Pure Java JDBC driver converts directly to native API and sends through vendor specific network protocol (great for intranets)
docsity.com
Java application (^) Data source
JDBC API JDBC-ODBC Bridge^ ODBC API ODBC Layer
application process
ODBC process
docsity.com
CCTM: Course material developed by James King ([email protected])
CCTM: Course material developed by James King ([email protected])
network
Java application Data source
JDBC API JDBC Driver
application process
JDBC Driver Server
Native Driver
Intermediate data access server: Gateway for multiple database server
docsity.com
JDBC Driver Manager
ODBC Oracle Driver XYZ Driver
Access Oracle xyzBase CCTM: Course material developed by James King ([email protected])
by the database
docsity.com
The forName method of Class loads the specified JDBC driver and initialises the DriverManager.
Object. The Connection Object is used to communicate with the database
specified in getConnection.
which can be used to send SQL statements to the connected database.
CCTM: Course material developed by James King ([email protected])
4 Use executeQuery or executeUpdate methods in Statement to search or modify
the database. (Searches produce a ResultSet object)
5 Process the ResultSet or handle any errors
6 Close Statement object and close the Connection when you have no more
statements to send.
docsity.com
Statement executeQuery ResultSet
“Select blah blah”
“Delete blah blah”
Statement executeUpdate
Once you have a statement object you can send SQL queries and updates to the database. Queries return a ResultSet object and updates return the number of records affected.
int
SQL is placed into the statement object
Statement.executeQuery returns any found database records
SQL is placed into the statement object
Statement.executeUpda te returns the number of records affected
CCTM: Course material developed by James King ([email protected])
o A JDBC driver is always needed to connect to a database
o Loading a driver requires the class name of the driver. For
JDBC-ODBC: sun.jdbc.odbc.JdbcOdbcDriver Oracle driver: oracle.jdbc.driver.OracleDriver mySQL: org.gjt.mm.mysql.Driver
o The class for the name of the driver is loaded using the static
Class.forName("org.gjt.mm.mysql.Driver"); This loads and initializes the driver. It is possible to load several drivers.
docsity.com