2

I'm using a JDBC Connection with autocommit turned off. In my cleanup method I want to check to ensure that there is not a transaction currently in progress but I can't see any way of obtaining this information. How can I find out if a transaction is in progress given a JDBC Connection?

Update

Although there's nothing in JDBC natively, the Tomcat JDBC connection pool has the concept of interceptors and I'm wondering if one could be written to track transactions at that level.

1 Answers1

0

JDBC Connection doesnt have any helper methods to know the status, but if you can get javax.transaction.UserTransaction, you can use "getStatus" method to find the status. More info on oracle site.

CuriousMind
  • 3,143
  • 3
  • 29
  • 54
  • 1
    When you use JDBC without any additional things like distributed transactions, then there is no UserTransaction. – Mark Rotteveel Feb 03 '13 at 15:38
  • I'm trying to avoid transaction managers if possible because they're unnecessary overhead for me. Although there's no obvious way of doing this cleanly I might end up just committing anyway whenever a connection is closed. –  Feb 03 '13 at 15:42