To create a forward only updatable result set, the
statement has to be created with concurrency mode
ResultSet.CONCUR_UPDATABLE and type
ResultSet.TYPE_FORWARD_ONLY.
The default type is
ResultSet.TYPE_FORWARD_ONLY.
Example of using ResultSet.updateXXX() +
ResultSet.updateRow() to update a row:
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery(
"SELECT FIRSTNAME, LASTNAME, WORKDEPT, BONUS " +
"FROM EMPLOYEE");
while (uprs.next()) {
int newBonus = uprs.getInt("BONUS") + 100;
uprs.updateInt("BONUS", newBonus);
uprs.updateRow();
}
Example of using ResultSet.deleteRow() to delete a row:
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery(
"SELECT FIRSTNAME, LASTNAME, WORKDEPT, BONUS " +
"FROM EMPLOYEE");
while (uprs.next()) {
if (uprs.getInt("WORKDEPT")==300) {
uprs.deleteRow();
}
}