DEVFYI - Developer Resource - FYI

How to update a resultset programmatically? (new feature in JDBC 2.0)

JDBC Interview Questions and Answers


(Continued from previous question...)

How to update a resultset programmatically? (new feature in JDBC 2.0)

a. create a scrollable and updatable ResultSet object.

Statement stmt = con.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery("SELECT COLUMN_1,
COLUMN_2 FROM TABLE_NAME");

b. move the cursor to the specific position and use related method to update data and then, call updateRow() method.

uprs.last();
uprs.updateFloat("COLUMN_2", 25.55);//update last row's data
uprs.updateRow();//don't miss this method, otherwise,
// the data will be lost.

(Continued on next question...)

Other Interview Questions