【问题标题】:error in your SQL syntax near (?,?,?)(?,?,?) 附近的 SQL 语法错误
【发布时间】:2015-11-02 18:54:32
【问题描述】:

我在网上冲浪,并不搜索我需要的东西。所以请你帮助我。 当我尝试在 Eclipse 中执行此 SQL 语句时

private final String INSERT_ = "INSERT INTO department VALUES (?, ?, ?)";

我有下一个错误:您的 SQL 语法有错误;检查与您的 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!");
}

提前致谢!

【问题讨论】:

  • I surf the net and don't search what I need. 是的,我在 SO 上注意到了很多。

标签: java mysql eclipse


【解决方案1】:

您不应将 SQL 字符串传递给 executeUpdate,因为您的 PreparedStatement 已经使用 SQL 字符串 + 参数进行了初始化。

改变

stmt.executeUpdate(INSERT_);

stmt.executeUpdate();

【讨论】:

    猜你喜欢
    • 2016-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    • 2016-03-12
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多