开发者

Transaction state in JDBC

开发者 https://www.devze.com 2022-12-08 06:11 出处:网络
Is there a way to know开发者_JAVA技巧 if a transaction is in an \"ongoing\" state in JDBC? I found nothing in the Connection API.

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消