简体   繁体   中英

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

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

you mixed the parameters, this should be the right code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM