gpt4 book ai didi

java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : and executeUpdate won't work

转载 作者:太空宇宙 更新时间:2023-11-03 10:51:26 24 4
gpt4 key购买 nike

大家好!我有这个程序检查当前密码是否与数据库中的密码匹配。然后新密码应该更新数据库中的当前密码。密码被转换成 md5 结构。现在,除了数据库不会更新外,一切都完美无缺。出现 MySQLSyntaxErrorException 并且 executeUpdate 方法也将不起作用。任何帮助都感激不尽。提前致谢!

if(!rs.next()){
JOptionPane.showMessageDialog(null, "Please Retype your password.");
response.sendRedirect("/Project1/ChangePassword.jsp");
}else{
JOptionPane.showMessageDialog(null, "RESULTSET");
pswrd = rs.getString(1);

if(md5CurrentPasswrd.equals(pswrd)){
if(newPassword.equals(confirmPassword)){
digest.update(newPassword.getBytes(), 0, newPassword.length());
md5NewPasswrd = new BigInteger(1, digest.digest()).toString(16);

Connection conn2 = null;
String conStr = "jdbc:mysql://localhost:3306/chkdb?user=root&password=";
conn2 = DriverManager.getConnection(conStr);

PreparedStatement prepStmt = conn2.prepareStatement("UPDATE accounts SET password=? /n"
+ " WHERE password=?");
prepStmt.setString(1,md5NewPasswrd);
prepStmt.setString(2,md5CurrentPasswrd);

JOptionPane.showMessageDialog(null, "Updated1!"); //The program passes this.

prepStmt.executeUpdate();
prepStmt.close();
JOptionPane.showMessageDialog(null, "Updated2!"); //The program does not reach this.
response.sendRedirect("/Project1/summary.jsp");
}else{
JOptionPane.showMessageDialog(null, "Passwords did not match!");
response.sendRedirect("/Project1/summary.jsp");
}
}
}

最佳答案

/n 应该是 \n 或者只是空格。

关于java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : and executeUpdate won't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24647194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com