Question

Am using struts 1.3.8 framework in netbeans 6.9 and I want to update a value in the database by using preparedStatement. It keeps giving mew an error that ( No value specified for parameter 3) and I don't know what is that parameter cause am setting a value by defining the id. I am appreciating your hard work and hope you help me with that.

This is my code:

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);
}

and this is the error msg:

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

Was it helpful?

Solution

Drop the values part. The UPDATE statement has no values part.

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

(VALUES is part of the INSERT statement.)

OTHER TIPS

The string you're passing to prepareStatement contains 4 placeholders (the ?), but you're providing values for only 2 of them (the setInt).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top