这是我在用户想要更改密码时编写的代码。
s2.executeUpdate("UPDATE user SET AES_ENCRYPT(password='"+newpw1+"','key') WHERE uid='"+pubvar.uid+"')");
但它不起作用,有人可以为我更正并发布吗? 感谢。
答案 0 :(得分:0)
UPDATE user
SET password = AES_ENCRYPT('" + newpw1 + "','key')
WHERE uid = '" + pubvar.uid + "')
更好地使用PreparedStatement
来阻止SQL Injection
。
String _upd = "UPDATE user SET password = AES_ENCRYPT(?,'key') WHERE uid = ?)";
PreparedStatement pstmt = con.prepareStatement(_upd);
pstmt.setString(1, newpw1);
pstmt.setString(2, pubvar.uid);
pstmt.executeUpdate();