SQL 1064 Syntax Error using a JDBC prepared statement

扶醉桌前 提交于 2019-12-02 01:48:34

You're passing an string representing an invalid SQL statement to the executeUpdate() method when you don't need to. Try just doing prep.executeUpdate();.

In your last line you don't need pass the variable query.

So change

 prep.executeUpdate(query);

For:

 prep.executeUpdate();

The main error is here:

 // incorrect
 prep.executeUpdate(query);

 // correct
 prep.executeUpdate();

But please try to put your SQL in the following form:

UPDATE table_name(field1, field2, field3) VALUES(?, ? ,?)

This will prevent your code from breaking if there is an update to the table.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!