大家好!我有这个程序,检查当前密码是否与数据库中的密码匹配。然后,新密码应更新数据库中的当前密码。密码转换为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");
}
}
}
答案 0 :(得分:2)
/n
应为\n
或仅为空格。
答案 1 :(得分:2)
从
更改您的查询UPDATE accounts SET password=? /n"
+ " WHERE password=?
要
UPDATE accounts SET password=? WHERE password=?