Re: Rollback not working





Ok, then your savepoint stuff is irrelevant. You are doing a simple
series of transactions, each one being a simple execution of the
prepared statement. Because your transaction is a single statement,
you don't even need to mess with autoCommit:

for (Iterator iter = burstAssignments.iterator(); iter.hasNext(); )
{
try {
pStmt.setInt(1, valSentId.intValue());
pStmt.setInt(2, burstAssignment.getId().intValue());
pStmt.execute(); // if it succeeds it is committed, else it
is not.
}
catch (Exception ex) {
ex.printStackTrace();
}

if you have any other code that wants a multi-statement tx, then it's:

con.setAutoCommit(false);
boolean didAnythingThatWeNeedToRollback;

for (Iterator iter = burstAssignments.iterator(); iter.hasNext(); )
{
try {
didAnythingThatWeNeedToRollback = false;

// do first update...
pStmt.setInt(1, valSentId.intValue());
pStmt.setInt(2, burstAssignment.getId().intValue());
pStmt.execute();
didAnythingThatWeNeedToRollback = true;

// do subsequent updates
pStmt2.setInt(1, ...);
pStmt2.execute();

con.commit();
}
catch (Exception ex) {
if (didAnythingThatWeNeedToRollback) con.rollback();
ex.printStackTrace();
}

Joe Weinstein at BEA Systems.

.