欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java学习笔记-JDBC 3 博客分类: Java学习笔记 JDBCJavaSQL 

程序员文章站 2024-03-01 20:08:04
...

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
   }
}
 
相关标签: JDBC Java SQL