XA和编程式的事务代码解决!
来源:互联网 发布:隔音通风器 知乎 编辑:程序博客网 时间:2024/06/07 23:26
Connection has already been created in this tx context for pool named jnboracle.
Illegal attempt to create connection from another pool: testpool
怎麽办?database is oracle !
1。connection pool必须是扩展了tx的DriveClass,如:drive classname:oracle.jdbc.xa.client.OracleXADataSource;
2。DataSource 必须是TxDataSource。
3。代码中从jndi中取得相应的DataSource,进行操作便OK
至于具体console操作你该知道咯!
以下是我的Transaction测试代码
---------------------------------
public class JDBCTransaction{
public final String UT_JNDI_Name = "javax.transaction.UserTransaction";
public final String DS_JNDI_Name1 = "AndyDS1";
public final String DS_JNDI_Name2 = "AndyDS2";
private Hashtable ht = null;
private Context ctx = null;
private UserTransaction ut = null;
private Connection conn1 = null;
private Connection conn2 = null;
private Statement stmt1 = null;
private Statement stmt2 = null;
private Context getInitialContext()throws NamingException{
ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://andy:7001");
return new InitialContext(ht);
}
public void CreateNewRecord(int id, String name, int age, String status) {
String SQL = "";
try{
ctx = getInitialContext();
ut = (UserTransaction)ctx.lookup(UT_JNDI_Name);
ut.begin();
DataSource ds1 = (DataSource)ctx.lookup(DS_JNDI_Name1);
conn1 = ds1.getConnection();
DataSource ds2 = (DataSource)ctx.lookup(DS_JNDI_Name2);
conn2 = ds2.getConnection();
conn1.setAutoCommit(false);
conn2.setAutoCommit(false);
stmt1 = conn1.createStatement();
stmt2 = conn2.createStatement();
SQL = "insert into t1 values(" + id + ", '" + name + "', '" + status + "')";
stmt1.executeQuery(SQL);
System.out.println("SQL: " + SQL);
SQL = "insert into t2 values(" + id + " ," + age + ")";
stmt2.executeQuery(SQL);
System.out.println("SQL: " + SQL);
ut.commit();
System.out.println("Transaction commit !");
}
catch(Exception e){
e.printStackTrace();
try{
ut.rollback();
System.out.println("Transaction rollback !");
}
catch(Exception e1){
e1.printStackTrace();
}
}
}
}
你可以用我的代码试一试,我没遇到问题。
- XA和编程式的事务代码解决!
- Spring的声明式事务和编程式事务详解
- Spring的 编程式事务和声明式事务
- Spring的声明式事务和编程式事务详解
- spring的编程式事务
- 编程式事务和声明式事务
- 编程式事务和声明式事务
- 声明式事务和编程式事务
- 【spring 6】Spring和Hibernate的整合:编程式事务
- 事务声明声明式事务和编程式事务介绍
- 事务声明声明式事务和编程式事务介绍
- spring管理事务声明式事务和编程式事务
- 事务声明声明式事务和编程式事务介绍
- 事务声明声明式事务和编程式事务介绍
- 采用编程式事务
- Spring编程式事务
- hibernate编程式事务
- Spring编程式事务
- Inline Hook IofCallDriver 截获所有IRP
- > Multi Transactions
- SOA与中间件、基础件的发展
- 声明:主要文章已经搬迁到博客园http://oscarxie.cnblogs.com/
- Forms 验证后无法登陆
- XA和编程式的事务代码解决!
- 机械行业基础数据复杂多变的原因探询
- 断开GPRS连接
- ASPxPivotGrid CollapseAll 方法为什么不起作用
- 推荐几篇有关SOA架构及实施的文章
- Using Microsoft Word 2007 publish blog
- 手忙脚乱的背后
- 列拆分
- WSE 3.0 for Microsoft .NET文档翻译系列索引