Reputation: 83
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
Reputation: 16037
you mixed the parameters, this should be the right code
pre.setInt(2, shipmentNumber);
pre.setString(1, currentLocation);
Upvotes: 5
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