大家好!我有这个程序,用于检查当前密码是否与数据库中的密码匹配。然后,新密码应更新数据库中的当前密码。密码将转换为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
或只是空格。