我在数据库中有一个用户记录。我应该使用哪种查询来更新特定用户的project_key
属性(通过其login
键找到)。我试图选择用户,然后使用结果集的updateString
方法。我也将结果集设置为TYPE_SCROLL_INSENSITIVE
和CONCUR_UPDATABLE
,但这没有任何作用。那么查询应该是什么?提前致谢。
最佳答案
使用PreparedStatement的executeUpdate()
String update = "UPDATE table SET project_key=? WHERE login=?";
PreparedStatement pstmt = conn.preparedStatement(update);
pstmt.setString(1, newKey);
pstmt.setString(2, userLogin);
int testForUpdate = pstmt.executeUpdate();
System.out.println(int>0?"Update was done":"No update occured");