org.apache.jasper.JasperException: javax.servlet.ServletException: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
PreparedStatement st=conn.prepareStatement("insert into products (pname,pfl,pb,pdes,price)values('"+pname+"','"+pfl+"','"+pb+"','"+pdes+"',"+price+")");
int i=st.executeUpdate(); //老是说这句有错误!!!

解决方案 »

  1.   

    最后price那没加单引号,改成如下:PreparedStatement st=conn.prepareStatement("insert into products (pname,pfl,pb,pdes,price)values('"+pname+"','"+pfl+"','"+pb+"','"+pdes+"','"+price+"')");
      

  2.   

    可以把sql语句赋值在mysql去运行 检查sql是否正确
    qq 1543150073 互相学习
      

  3.   

    对不起发错了  上面代码是正确的String s="update products set 'pname="+pname+"','pfl="+pfl+"','pb="+pb+"','pdes="+pdes+"',price="+price+" where id="+id; 
         PreparedStatement st=conn.prepareStatement(s);
          int i=st.executeUpdate();这个代码有问题的  实在不好意思~~~
      

  4.   

    [Quote=引用 1 楼  的回复:]
    对不起发错了 上面代码是正确的String s="update products set 'pname="+pname+"','pfl="+pfl+"','pb="+pb+"','pdes="+pdes+"',price="+price+" where id="+id;  
      PreparedStatement st=conn.prepareStatement(s);
      int i=st.executeUpdate();