Java:查看与您的MySQL服务器版本对应的手册,以了解使用near';的正确语法;?值(';23';)';在1号线

Java:查看与您的MySQL服务器版本对应的手册,以了解使用near';的正确语法;?值(';23';)';在1号线,java,mysql,Java,Mysql,我试图更新我的数据库表,但遇到MySQLSyntaxErrorException。我可以知道如何解决这个错误吗 谢谢!:) 这就是我得到的错误: Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL serve

我试图更新我的数据库表,但遇到MySQLSyntaxErrorException。我可以知道如何解决这个错误吗

谢谢!:)

这就是我得到的错误:

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.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 '?VALUES ('23')' at line 1

sql
update
语句不使用
VALUES
关键字(即用于插入)

使用以下准备好的声明

String updateTableSQL = "UPDATE department  SET agentID = ?"
PreparedStatement preparedStatement = 
       dbConnection.prepareStatement(updateTableSQL);
preparedStatement.setInt(1, id);

// execute update SQL stetement
preparedStatement.executeUpdate();
注意


我可以想象,您还需要某种where子句,否则您将更新所有记录

Hmm,我仍然得到相同的错误tho::这将为表中的所有行设置agentID,而OP可能不想这样做。
String updateTableSQL = "UPDATE department  SET agentID = ?"
PreparedStatement preparedStatement = 
       dbConnection.prepareStatement(updateTableSQL);
preparedStatement.setInt(1, id);

// execute update SQL stetement
preparedStatement.executeUpdate();