Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Savepoints and transactions

 
Tripp Bishop
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy all,
Here's my question. Given the following code:
Connection conn = null;
SavePoint savepoint = null;

try {
conn = ConnectionPool.getConnection();
dao mydao = new mydao();
mydao.task(conn);
savepoint = conn.setSavepoint("Beginning");
conn.commit();
mydao.anotherTask(conn);
conn.commit();
mydao.finalTask(conn);
conn.commit();
} catch(Exception e) {
conn.rollback(savepoint); // try/catch removed for clarity
} finally {
conn.close(); // try/catch removed for clarity
}
If I were to rollback to this save point (which is actually back to before the first command) and then closed the connection, would the transaction be terminated or would it be dangling on the database server, waiting for a commit() or rollback() to take place?
Thanks,
Tripp
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic