You use special parameters in the Connection.prepareStatement or Connection.createStatement methods to specify the updatability, scrollability, and holdability of a ResultSet.
String s;
String stmtsrc;
Connection con;
Statement stmt;
ResultSet rs;
…
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE); 1
// Create a Statement object
// for a scrollable, updatable
// ResultSet
stmtsrc = "SELECT EMPNO, PHONENO FROM EMPLOYEE " +
"FOR UPDATE OF PHONENO";
rs = stmt.executeQuery(stmtsrc); // Create the ResultSet 3
rs.afterLast(); // Position the cursor at the end of
// the ResultSet 4a
while (rs.previous()) { // Position the cursor backward
s = rs.getString("EMPNO"); // Retrieve the employee number 4d
// (column 1 in the result
// table)
System.out.println("Employee number = " + s);
// Print the column value
if (s.compareTo("000010") == 0) { // Look for employee 000010
rs.updateString("PHONENO","4657"); // Update their phone number
rs.updateRow(); // Update the row
}
}
rs.close(); // Close the ResultSet 5
stmt.close(); // Close the Statement 6