【问题标题】:How to resolve MySQLSyntaxErrorException exception?如何解决 MySQLSyntaxErrorException 异常?
【发布时间】:2018-01-07 15:56:53
【问题描述】:

我在创建更新 jsp mysql 时不断收到 MySQLSyntaxErrorException。

String id_user = request.getParameter("id_login");    
String name_cust = request.getParameter("name_cust");
String password = request.getParameter("password");
String email = request.getParameter("email");
String no_phone = request.getParameter("no_phone");


Statement st = CON.createStatement();
//ResultSet rs;
int i = st.executeUpdate("UPDATE signup SET id_login='"+id_user+"',name_cust='"+name_cust+"', password='"+password+"'email='"+email+"',no_phone='"+no_phone+"', WHERE id_user='"+id_user+"'");

【问题讨论】:

标签: java mysql sql jsp jdbc


【解决方案1】:

您在WHERE 之前有一个额外的,,而您在EMAIL 之前缺少一个。

"UPDATE signup SET id_login=?, name_cust=?, password=?, email=?, no_phone=? WHERE id_user=?"

另外,您应该使用PreparedStatement,以避免任何 SQL 注入。

【讨论】:

    【解决方案2】:

    SQL语句语法错误,试试这个

    int i = st.executeUpdate("UPDATE signup SET id_login='"+id_user+"',name_cust='"+name_cust+"', password='"+password+"'email='"+email+"',no_phone='"+no_phone+"'WHERE id_user='"+id_user+"'");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-20
      • 2017-09-15
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多