利用Mysql进行update时,出现You have an error in your SQL syntax check the manual that corresponds to your My

来源:互联网 发布:linux cp -r 编辑:程序博客网 时间:2024/06/07 20:08

 总是出现You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax ...... at line 1错误。

代码如下:

   ps = conn.prepareStatement("update admin set aid = ?,username = ?,password = ?,password2 = ?"
     + "where aid like ? ");
   ps.setInt(1,admin.getAid());
   ps.setString(2, admin.getUsername());
   ps.setString(3, admin.getPassword());
   ps.setString(4, admin.getPassword2());
   ps.setInt(5, aid);

这段代码没有什么大问题,就是在update的语句中少了个空格!!!

在关键字where后面少了个空格,导致where和参数password2的值连在了一起,出现语法错误。

正确的代码是:
 ps = conn.prepareStatement("update admin set aid = ?,username = ?,password = ?,password2 = ?"
     + " where aid like ? ");