java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax
上一节
下一节
问题描述:在采用preparedStatement注册用户时,控制台输出报错如下图:


报错代码:
java.sql.SQLSyntaxErrorException: 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 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)。
解决方案:
如果确认SQL语句没有写错的情况下,那么可能是preparedStatement的executeUpdate()方法导致的。
这是因为在创建预处理对象 conn.prepareStatement(strSQL)的时候,对SQL语句已经进行了预编译,所以在执行更新executeUpdate()时不需要再次传入strSQL参数,如果传入,则会报上述错误。

