简体   繁体   中英

Update user password via JDBC not working

This is the relevant bit of code,

createconn = new CreateConnection();
con = createconn.connect_to_database();
String SQL = "UPDATE User SET Password = SHA2(?,512) WHERE Login = ? AND Password = SHA2(?,512)";
stmt = con.prepareStatement(SQL);
stmt.setString(1, NewPassword);
stmt.setString(2, Login);
stmt.setString(3, CurrentPassword);
int count = stmt.executeUpdate();
System.out.println("Rows affected: " + count);

count always is set to 0, ie, no rows are updated, even when current password is correct. What's worse, no exception is generated. (even when current password is wrong)

When I use a fixed statement (using fixed values for the three parameters), the code works, just not when written like this.

This whole code is inside a function which takes the three parameters as arguments.

Any help is appreciated.

PASSWORD is a reserved word, maybe the workbench is a bit more lenient/intelligent. Try adding back ticks around.

`Password`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM