Transaction state in JDBC
Is there a way to know开发者_JAVA技巧 if a transaction is in an "ongoing" state in JDBC? I found nothing in the Connection API.
Thanks
JDBC does not track the transaction state. It is the job of DB to track the transaction state.
Given that, you still have two ways on tracking/knowing the transaction states.
You can make a sql call to your db to ask for transaction specific detail. for oracle, it will be in v$transaction table in suggested in this post.
SELECT COUNT(*)
FROM v$transaction t, v$session s, v$mystat
WHERE t.ses_addr = s.saddr AND s.sid = m.sid AND ROWNUM = 1;
Another solution is to use transaction manager code in some common frameworks, such as hibernate (I believe Spring has it too).
public interface Session {
public abstract org.hibernate.Transaction getTransaction();
}
public Transaction {
public abstract boolean wasRolledBack() throws org.hibernate.HibernateException;
public abstract boolean wasCommitted() throws org.hibernate.HibernateException;
public abstract boolean isActive() throws org.hibernate.HibernateException;
}
精彩评论