Databases Reference
In-Depth Information
Driver Manager
getConnection(?.?.?)
CreateStatement()
Connection
PrepareCall(?)
PrepareStatement(?)
Statement
PreparedStatement
CallableStatement
setXXX(?.?)
execute()
setXXX(?.?)
executeQuery()
execute()
executeQuery(?)
setXXX(?.?)
executeQuery()
setXXX(?.?)
executeUpdate()
executeUpdate(?)
setXXX(?.?)
executeUpdate()
getUpdateCount()
getUpdateCount()
True
False
Null
ResultSet
ResultSet
ResultSet
ResultSet
next()
getXXX(?.?)
getUpdateCount()
next()
getXXX(?.?)
next()
getXXX(?.?)
Update
Count
Update
Count
Update
Count
Records
Records
Records
Figure 5-1 Different path for an SQL statement in a JDBC program
Each of the three classes, Statement, PreparedStatement, and
CallableStatement, provides three different methods to execute a query:
executeQuery: This method is used to select the rows and return a resultSet
object.
executeUpdate: This method is used to update the database and return the
update count.
execute method: This method returns a Boolean value of true if the output of
the query is a ResultSet object ( SELECT ) and false if its an update statement
( INSERT , UPDATE , or DELETE ).
The getUpdateCount method can be used to get the number of rows updated in
the database by the SQL statement. The get XXX method of the ResultSet object
can be used to fetch the individual rows.
For CallableStatement, each of these methods has a slightly different meaning.
The executeQuery method is used when the stored procedure returns a
ResultSet, where execute is used when the stored procedure returns multiple
ResultSets.
Search WWH ::




Custom Search