KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > test > jdbc > TestXA


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.test.jdbc;
6
7 import java.sql.Connection JavaDoc;
8 import org.h2.jdbcx.JdbcDataSource;
9
10 public class TestXA {
11     
12     int notYetImplemented;
13     
14     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
15         Class.forName("org.h2.Driver");
16
17
18 // InitialContext ictx = new InitialContext();
19
// ictx.rebind(USER_TRANSACTION_JNDI_NAME, jotm.getUserTransaction());
20

21         JdbcDataSource ds1 = new JdbcDataSource();
22         ds1.setPassword("");
23         ds1.setUser("sa");
24         ds1.setURL("jdbc:h2:db1H2");
25
26         JdbcDataSource ds2 = new JdbcDataSource();
27         ds2.setPassword("");
28         ds2.setUser("sa");
29         ds2.setURL("jdbc:h2:db2H2");
30
31 // UserTransaction ut = (UserTransaction) ictx.lookup("UserTransaction");
32
// ut.begin();
33

34         Connection JavaDoc c1 = ds1.getXAConnection().getConnection();
35         c1.setAutoCommit(false);
36         Connection JavaDoc c2 = ds2.getXAConnection().getConnection();
37         c2.setAutoCommit(false);
38
39         c1.createStatement().executeUpdate("create table test(id int, teste varchar(255))");
40         c2.createStatement().executeUpdate("create table test(id int, teste varchar(255))");
41
42
43 // ut.rollback();
44
c1.close();
45         c2.close();
46
47 // jotm.stop();
48
// System.exit(0);
49

50     }
51 }
52
Popular Tags