Java Reference
In-Depth Information
An application can determine if the changes a result set makes are visible to the
result set itself by calling these DatabaseMetaData methods:
 
ownUpdatesAreVisible(int ResultSet.TYPE_XXX)
 
ownDeletesAreVisible(int ResultSet.TYPE_XXX)
 
ownInsertsAreVisible(int ResultSet.TYPE_XXX)
The DatabaseMetaData interface also provides the following methods that allow an
application to determine whether a JDBC driver can detect changes for a particular
result-set type:
 
insertsAreDetected(ResultSet.TYPE_XXX)
 
deletesAreDetected(ResultSet.TYPE_XXX)
 
updatesAreDetected(ResultSet.TYPE_XXX)
If these methods return true, the following methods can be used to detect changes to
a ResultSet:
 
wasInserted()
 
wasDeleted()
 
wasUpdated()
Remember that if you modify data in a ResultSet object, the change will always be
visible if you close the ResultSet and reopen it by executing the same query again
after the changes have been made.
Another way to get the most recent data is to use the method refreshRow(), which
gets the latest values for a row straight from the database. This is done by positioning
the cursor to the desired row and calling refreshRow(), as shown here:
rs.absolute(3);
rs.refreshRow();
The result set should be TYPE_SCROLL_SENSITIVE; if you use the
method refreshRow() with a ResultSet object that is
TYPE_SCROLL_INSENSITIVE, refreshRow() does nothing.
Note
Another way to get data from a database is to use a RowSet object. RowSets add
JavaBeans support to the functionality of the ResultSet, as explained in the next
section .
RowSets
A RowSet is an object that contains a set of rows from a result set or some other
source of tabular data, like a fi le or spreadsheet. RowSet is an extension of ResultSet,
Search WWH ::




Custom Search