to update a column value in the current row. In a scrollable ResultSet object, 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 the NAME column in the fifth row of the ResultSet object rs and then uses the method updateRow to update the data source table from which rs was derived. rs.absolute(5); // moves the cursor to the fifth row of rs rs.updateString("NAME", "AINSWORTH"); // updates the // NAME column of row 5 to be AINSWORTH rs.updateRow(); // updates the row in the data source -----摘自jdk文档java.sql.ResultSet
用stmt.executeUpdate("update admin.sys_users set USER_NAME='NNNNNN' where user_id=17");这种方法应该可以更新数据库的啊。 CachedRowset可以从ResultSet得到,但是这样做是为了有时在网络上访问数据库时在得到结果集后可以关闭数据库链接才用的吧,如果用ResultSet的话,关闭数据库链接后里面的记录应该就释放掉了。不知我说的对不对。大家一起讨论。
select XXXXX from tablename where condition for update 最好用PreparedStatement
rs.updateString("NAME", "AINSWORTH"); // updates the
// NAME column of row 5 to be AINSWORTH
rs.updateRow(); // updates the row in the data source
-----摘自jdk文档java.sql.ResultSet
CachedRowset可以从ResultSet得到,但是这样做是为了有时在网络上访问数据库时在得到结果集后可以关闭数据库链接才用的吧,如果用ResultSet的话,关闭数据库链接后里面的记录应该就释放掉了。不知我说的对不对。大家一起讨论。
最好用PreparedStatement
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select 列名1,列名2 from table ");
rs.absolute(5);
rs.updateString("列名1", "value");
rs.updateRow();
rs.close();
stmt.close();
这样是可以的,但是在select语句中不能有group by,order by等等,会导致取不到rowid,就不能更新,限制还挺多的。