Databases Reference
In-Depth Information
executeQuery: Use this method when a single result set is expected.
executeUpdate: Use this method when no result set is expected.
Example 5-9 gives the code snippet from the createPorder method of the
application code. The method calls a stored procedure named createOrder . The
stored procedure code is given in the class CreateOrder . The stored procedure
has two IN parameters and one OUT parameter. The stored procedure should be
registered before using it. 5.5, “Stored procedure support” on page 219 explains
how to register the stored procedure.
Example 5-9 Calling a stored procedure using CallableStatement object
CallableStatement cstmt;
cstmt = con.prepareCall("call createOrder(?,?,?)");
cstmt.setInt(1,poid);
cstmt.setString(2,cart);
cstmt.registerOutParameter(3, Types.VARCHAR);
cstmt.executeUpdate();
return cstmt.getString(3);
ResultSet
The executeQuery method of Statement, PreparedStatement, and
CallableStatement returns the ResultSet object as an output of the query.
The ResultSet object maintains a cursor to the current row of the result set of a
query. This cursor can be advanced to the next row by using the next method of
this object. The cursor by default can only be moved forward and is read-only.
The columns value for the current row can be fetched by calling the get XXX
method of the ResultSet object where XXX denotes the data type of the column.
The get XXX takes the column number or name for the current row as an input.
Once all the rows are fetched, the next method returns an exception.
Example 5-4 on page 209, Example 5-5 on page 210, and Example 5-7 on
page 211 use the ResultSet object to retrieve the result of the query.
By default, the cursor cannot be moved backward and updated. Cursors can be
moved backward or moved directly to a specific row by defining the scrollability
of the ResultSet object. Similarly, the cursor can be updated by defining the
updateability of the ResultSet object.
The following three properties for the ResultSet can be set while creating the
Statement object:
resultSetType
resultSetConcurrency
Search WWH ::




Custom Search