2010. 6. 22. 12:01
Programming/Java
출처 : http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html
Statement stmt = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
// rs will be scrollable, will not show changes made by others,
// and will be updatable
// rs will be scrollable, will not show changes made by others,
// and will be updatable
-
to update a column value in the current row. In a scrollable
ResultSetobject, the cursor can be moved backwards and forwards, to an absolute position, or to a position relative to the current row. The following code fragment updates theNAMEcolumn in the fifth row of theResultSetobjectrsand then uses the methodupdateRowto update the data source table from whichrswas derived.rs.absolute(5); // moves the cursor to the fifth row of rs rs.updateString("NAME", "AINSWORTH"); // updates the //
NAMEcolumn of row 5 to beAINSWORTHrs.updateRow(); // updates the row in the data source - to insert column values into the insert row. An updatable
ResultSetobject has a special row associated with it that serves as a staging area for building a row to be inserted. The following code fragment moves the cursor to the insert row, builds a three-column row, and inserts it intorsand into the data source table using the methodinsertRow.rs.moveToInsertRow(); // moves cursor to the insert row rs.updateString(1, "AINSWORTH"); // updates the // first column of the insert row to be
AINSWORTHrs.updateInt(2,35); // updates the second column to be35rs.updateBoolean(3, true); // updates the third column totruers.insertRow(); rs.moveToCurrentRow();

