Java Reference
In-Depth Information
// output all rows to the console
rowSet.beforeFirst();
while (rowSet.next()){
for(int j=1; j<=rowSet.getMetaData().getColumnCount(); j++){
System.out.print( rowSet.getObject(j)+"\t");
}
System.out.println();
}
rowSet.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
If you insert a row without supplying a value for every column in the row, the default value for the
column will be used if there is one. Otherwise, if the column accepts SQL NULL values, a NULL will be
inserted. Failing either of those, a SQLException will be thrown.
Caution
A SQLException will be thrown if a required table column is missing in the
updatable RowSet , so the query used to get the updatable RowSet object should
generally select all columns.
Deleting a Row
Deleting a row in an updatable RowSet is very simple. All you have to do is move the cursor to the row
you want to delete and call the method deleteRow() . The example in the following code snippet
shows how to delete the third row in a ResultSet by moving the cursor to the third row and using the
deleteRow() method:
rowSet.absolute(3);
rowSet.deleteRow();
Seeing Changes Made to an Updatable RowSet
Changes made to an updatable RowSet are not necessarily visible, either to the RowSet itself or to
other open transactions. An application can determine if the changes a ResultSet makes are visible
to the ResultSet itself by calling the appropriate DatabaseMetaData methods.
One way to get the most recent data from a table 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();
Note
The RowSet should be TYPE_SCROLL_SENSITIVE; otherwise, refreshRow() does
nothing.
RowSet Events
Search WWH ::




Custom Search