Professional Documents
Culture Documents
JDBC Objects: J2EE Complete Reference Jim Keogh
JDBC Objects: J2EE Complete Reference Jim Keogh
Chapter 6
J2EE Complete Reference
Jim Keogh
Agenda
JDBC Concept
JDBC Driver Types
JDBC Packages
Brief Overview of JDBC process
Database Connection
Connection Pool
Connect to Database
Loading the JDBC
Driver
Connecting to the Database
Process Data
Process Data returned by DBMS
Database Connection
(more than one way)
Using URL:
Database Connection
(more than one way)
Using user ID and password
Connection Pool
Connecting to database using
Connection Pool
Statement Objects
Contains methods:
1. executeQuery()
- Returns ResultSet objects that contains
rows, columns, metadata.
2. execute()
- Used when there may be multiple results
returned
3. executeUpdate()
- Used to execute DELETE and UPDATE queries
- Returns the number of rows affected.
PreparedStatement
SQL Query must be compiled before DBMS
processes the query.
Compiling occurs after one of the Statement class
execution method is called.
Compiling a query is an overhead.
Acceptable if query is called once.
Expensive if the query is called several times.
A SQL Query is precompiled using
PreparedStatement.
CallableStatement
Uses 3 types of parameters when
calling a stored procedure:
IN : Contains data that needs to be
passed to the stored procedure
OUT: Contains value that is returned by
stored procedure.
INOUT: Single parameter that is used to
pass and store parameter to and from
stored procedure.
ResultSet
SrollableResultSet
Usage
Implementation
Updatable ResultSet
Insert Row
Metadata
Metadata is data about data
J2EE component retrieves metadata
about the database by calling
getMetaData() of Connection object.
This method returns
DatabaseMetaData object containing
information about database and its
components.
Retrieving information
DatabaseMetaData object has the following functions
to retrieve the information contained in the object.