Java学习笔记-JDBC 3

Scrollable Result Sets

 

Statement stat = conn.createStatement(type, concurrency);
 
PreparedStatement stat = conn.prepareStatement(command, type, concurrency);

 

Type Values

 

Value Explanation
TYPE_FORWARD_ONLY The result set is not scrollable (default).
TYPE_SCROLL_INSENSITIVE The result set is scrollable but not sensitive to database changes.
TYPE_SCROLL_SENSITIVE The result set is scrollable and sensitive to database changes.

 

Concurrency Values

 

Value Explanation
CONCUR_READ_ONLY The result set cannot be used to update the database (default).
CONCUR_UPDATABLE The result set can be used to update the database.

 

 

 

Updatable Result Sets

 

Statement stat = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, 
    ResultSet.CONCUR_UPDATABLE);

 

The updateRow , insertRow , and deleteRow methods of the ResultSet class give you the same power as executing UPDATE , INSERT , and DELETE SQL statements.

 

String query = "SELECT * FROM Books";
ResultSet rs = stat.executeQuery(query);
while (rs.next())
{
   if (. . .)
   {
      double increase = . . .
      double price = rs.getDouble("Price");
      rs.updateDouble("Price", price + increase);
      rs.updateRow(); // make sure to call updateRow after updating fields
   }
}
 

你可能感兴趣的:(java,sql,jdbc)