Java Reference
In-Depth Information
Deleting a Row
Deleting a row in an UpdatableResultSet 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
result set by getting the ResultSet object, moving the cursor to the third row, and
using the deleteRow() method:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection ("jdbc:odbc:Contacts");
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(query);
rs.absolute(3);
rs.deleteRow();
Caution
Be aware that different JDBC drivers handle deletions in different ways.
Some remove a deleted row so that it is no longer visible in a result set,
and others insert a blank row where the deleted row used to be.
When you make a change to a ResultSet, the change may not necessarily be visible.
The next section explains the reasons.
Seeing Changes in ResultSets
Changes made to a ResultSet are not necessarily visible, either to the ResultSet itself
or to other open transactions. In this context, the terms visible and not visible have
the following meanings:
 
An update is visible if the updated value can be retrieved by calling the appropriate getter method
after making an update.
 
An update is not visible if the getter method still returns the initial column value.
Similarly, an inserted row is visible if it appears in the ResultSet after calling
insertRow(). Deletions are visible if deleted rows are either removed from the result
set or if deleted rows leave a hole in the result set.
There are a number of factors affecting the visibility of changes, including the
following:
 
JDBC driver implementation
 
Transaction isolation level in effect
 
Result-set type
Search WWH ::




Custom Search