java - 更新表时出错 [未为参数 3 指定值]

标签 java sql struts1

我在 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/

相关文章:

java - 我可以在 if 语句中声明一个数组吗?

php - 如何防止 PHP 中的 SQL 注入(inject)?

php - 我可以将我的 2 个选择查询合并为一个吗?

java - 我使用的是struts1,关于action名称

java - 点击历史项目显示无法在 hadoop 2.7.2 中连接

javascript - Crypto.js SHA1 与 MessageDigest java SHA1 : why different results?

java - Rest 和 Struts 1.x 结合在一起

java - struts 1 form bean线程安全吗?

java - 加载/浸泡测试已部署的 Java EE 应用程序的工具/技术?

sql - POSTGRES 根据值 n 生成 n 行