当我尝试执行 UPDATE
时,我收到此错误消息查询:
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 '?' at line 1
这是我的代码:
sql = "UPDATE object_1_ SET attr_2_ = ?";
prepared = dbConnection.prepareStatement(sql);
prepared.setString(1, "abc");
prepared.executeUpdate();
但是,如果我稍微更改代码并删除参数:
sql = "UPDATE object_1_ SET attr_2_ = 'abc'";
prepared = dbConnection.prepareStatement(sql);
prepared.executeUpdate();
然后就可以了。所以,我想知道我在这里做错了什么?
最佳答案
问题原来是代码实际上在做
prepared.executeUpdate(sql);
当它应该做的时候
prepared.executeUpdate();
关于java - 使用 JDBC 和预准备语句时 SQL 语法出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33476315/