keloch
keloch

Reputation: 83

Could anyone find out what i did wrong in this prepared statement?

I made a prepared statement for DB access, it dosent work though.. I'm not really sure what the problem is.

What it should do is take a integer and a string and update the DB according to this.

Here is the code. The connection to the DB itself works, this i know cause i can execute "normal" statements.

public void updateShipment(int shipmentNumber, String currentLocation)
        throws SQLException {

    String sql = "UPDATE shipments SET current_node=? WHERE shipment_id=?";
    con.setAutoCommit(false);
    pre = con.prepareStatement(sql);
    pre.setInt(1, shipmentNumber);
    pre.setString(2, currentLocation);
    pre.executeUpdate();
    con.commit();
    pre.close();
    con.setAutoCommit(true);
}

Upvotes: 3

Views: 105

Answers (2)

bpgergo
bpgergo

Reputation: 16037

you mixed the parameters, this should be the right code

pre.setInt(2, shipmentNumber);
pre.setString(1, currentLocation);

Upvotes: 5

ewan.chalmers
ewan.chalmers

Reputation: 16235

Looks like you get parameter 1 and 2 mixed up when you set them. Did you mean:

pre.setString(1, currentLocation);
pre.setInt(2, shipmentNumber);

Upvotes: 9

Related Questions