SQL语句:
select * from usrpsw limit 0, 5表格结构是

res是ResultSet的对象
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
res = stmt.executeQuery(sql);
res.first();
res.updateString( 1, "PR-10004 ");
res.updateRow();
结果如图:

参考:
http://www.exampledepot.com/egs/java.sql/UpdateRow.html
try {
// Create an updatable result set
Statement stmt = connection.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");
// Move cursor to the row to update
resultSet.first();
// Update the value of column col_string on that row
resultSet.updateString("col_string", "new data");
// Update the row; if auto-commit is enabled, update is committed
resultSet.updateRow();
} catch (SQLException e) {
}

本文介绍如何使用Java API更新SQL ResultSet中的数据。通过设置Statement对象的类型为可滚动和可更新,可以实现对查询结果集的修改。示例展示了如何更新一行中的特定列。

2263

被折叠的 条评论
为什么被折叠?



