我在 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);
}
这是错误消息:
ERROR Updating : Did not Update the itemQyt in the item table which the itemId is : 7 and the new Qyt is :9 java.sql.SQLException: No value specified for parameter 3
最佳答案
您传递给 prepareStatement
的字符串包含 4 个占位符(?
),但您只为其中 2 个占位符提供值(setInt
)。
关于java - 更新表时出错 [未为参数 3 指定值],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9037433/