0

我在 netbeans 6.9 中使用 struts 1.3.8 框架,我想通过使用preparedStatement. 它不断给我一个错误(没有为参数3指定值),我不知道那个参数是什么原因我通过定义id来设置一个值。我很感激你的辛勤工作,希望你能帮助我。

这是我的代码:

try{
    // update the item Qyt in the item table after checking it out
    PreparedStatement ps2 = (PreparedStatement) con.prepareStatement("UPDATE item SET itemQyt=? WHERE itemID=?"
             + " VALUES (?,?)");
    ps2.setInt(1, newQuantity);
    ps2.setInt(2, itemID);
    int updateRows = ps2.executeUpdate();
    ps2.close();

} catch (Exception e) {
    errors.add("SQLUpdatingItem", new ActionMessage("errors.SQLUpdatingItem"));
    System.out.println("ERROR Updating : Did not Update the itemQyt in the item table which the itemId is : " + itemID + " and the new Qyt is :" + newQuantity + " " + e);
}

这是错误消息:

错误更新:未更新 itemId 为 7 且新 Qyt 为:9 的 item 表中的 itemQyt java.sql.SQLException:未为参数 3 指定值

4

2 回答 2

1

您传递给的字符串prepareStatement包含 4 个占位符 (the ?),但您只为其中的 2 个 (the setInt) 提供值。

于 2012-01-27T17:32:07.490 回答
0

删除值部分。UPDATE 语句没有值部分。

"UPDATE item SET itemQyt=? WHERE itemID=?"

(VALUES 是 INSERT 语句的一部分。)

于 2012-01-27T17:37:10.500 回答