简体   繁体   中英

Java transaction - commit on conn doesn't

Suppose I have the following Java code fragment (where something like it is embedded in a legacy app)

...
try {
    con.setAutoCommit(false);
    updateSales = con.prepareStatement(updateString);
    updateTotal = con.prepareStatement(updateStatement);

    updateSales.setInt(1, e.getValue().intValue());
    updateSales.setString(2, e.getKey());
    updateSales.executeUpdate();
    updateTotal.setInt(1, e.getValue().intValue());
    updateTotal.setString(2, e.getKey());
    updateTotal.executeUpdate();
    con.commit();
} catch (SQLException e ) {
...

Assuming this is connecting to an SQL Server 2005 database (with the ms 2005 driver) - is there any reason that the con.commit would NOT commit the transaction?

  1. You haven't shown us SQL statements, so it is hard to say. Maybe you have strange condition in them so database cannot update/insert/delete any records?

  2. Check result of executeUpade() . It should give you 1 or more if any record was changed

  3. Maybe there is TRIGGER on database that blocks such operation. Is it possible to change database from some SQL editor with your updateString with hard coded values?

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