com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:和executeUpdate不能工作

时间:2014-07-09 06:58:56

标签: java mysql jdbc

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

2 个答案:

答案 0 :(得分:2)

/n应为\n或仅为空格。

答案 1 :(得分:2)

更改您的查询
UPDATE accounts SET password=? /n"
             + " WHERE password=?

UPDATE accounts SET password=? WHERE password=?