[英]Prepared statement to update an attribute for a specific user - JDBC
I have a user record in a database. 我在数据库中有一个用户记录。 What query should I use to update the
project_key
attribute of a specific user, I find by his login
key. 我应该使用哪个查询来更新特定用户的
project_key
属性,该查询由其login
键找到。 I tried to select the user and then use the updateString
method of the result set. 我试图选择用户,然后使用结果集的
updateString
方法。 I also made the result set TYPE_SCROLL_INSENSITIVE
and CONCUR_UPDATABLE
, but that didn't do anything. 我还设置了结果集
TYPE_SCROLL_INSENSITIVE
和CONCUR_UPDATABLE
,但没有执行任何操作。 So what should the query be? 那么查询应该是什么? Thanks in advance.
提前致谢。
Use PreparedStatement's executeUpdate() 使用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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.