[英]error in your SQL syntax near (?,?,?)
I surf the net and don't search what I need.我上网,不搜索我需要的东西。 So please you help me.
所以请你帮帮我。 When I try to execute this SQL statement in Eclipse
当我尝试在 Eclipse 中执行此 SQL 语句时
private final String INSERT_ = "INSERT INTO department VALUES (?, ?, ?)";
I have next error:You have an error in your SQL syntax;我有下一个错误:您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?, ?)' at line 1 This is my code
检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“?, ?, ?)”附近使用的正确语法这是我的代码
public void insert(int id, String name, String description) throws SQLException
{
Department result = null;
Connection conn = ConnectionManager.getConnection();
PreparedStatement stmt = conn.prepareStatement(INSERT_);
stmt.setInt(1, id);
stmt.setString(2, name);
stmt.setString(3, description);
stmt.executeUpdate(INSERT_);
System.out.println("Record is inserted into table!");
}
Thanks in advance!提前致谢!
You shouldn't pass the SQL String to executeUpdate
, since your PreparedStatement
was already initialized with the SQL String + the parameters. 您不应该将SQL String传递给
executeUpdate
,因为您的PreparedStatement
已经使用SQL String +参数初始化。
Change 更改
stmt.executeUpdate(INSERT_);
to 至
stmt.executeUpdate();
enter image description here this is my opinion,在这里输入图片描述这是我的意见,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.