在MySQL中插入数据时,如何解决“ java.sql.SQLSyntaxErrorException”错误?

时间:2019-03-23 01:48:06

标签: java mysql sql

我正在使用prepareStatement,并且出现java.sql.SQLSyntaxErrorException错误

query = "INSERT INTO instdb (" +
     "id," +
     "name," +
     "username," +
     "descr," +
     "tel," +
     "vk," +
     "ownerId," +
     "query," +
     "postId," +
     "parametr) VALUES" +
     "(?,?,?,?,?,?,?,?,?,?)";
stmt = con.prepareStatement(query);
stmt.setInt(1, maxid);
stmt.setString(2,user.getFull_name());
stmt.setString(3,username);
stmt.setString(4,caption);
stmt.setString(5,longestTel);
stmt.setString(6,vk);
stmt.setString(7,ownerId);
stmt.setString(8,addons.get(j));
stmt.setString(9,postId);
stmt.setString(10,param);
stmt.executeUpdate(query);

出现stmt.executeUpdate(query);错误

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 '?,?,?,?,?,?,?,?,?,?)

在这是另一个错误之前,但我已经解决了

1 个答案:

答案 0 :(得分:0)

您无需将查询放入准备好的语句的以下方法调用中。您已经将sql查询添加到准备好的语句中。

stmt.executeUpdate();