0 Replies Latest reply on Nov 18, 2008 4:22 AM by Sambhu Sasidharan

    JBoss Trans

    Sambhu Sasidharan Newbie

      I am new to JBoss Transaction, I tried to execute one example code. When code is executed, I can see than after each insert statement the value is reflected in the "target" table.

      I checked this by logging into SQLDeveloper and running the program in debug mode.

      I would like to know If I am making some mistake or my understanding is wrong.


      import java.util.*;
      import java.sql.*;
      import com.arjuna.ats.jta.*;
      import com.arjuna.ats.jta.UserTransaction.*;
      import com.arjuna.ats.*;
      import com.arjuna.ats.jdbc.TransactionalDriver;
      import javax.transaction.Status;
      
      import com.arjuna.ats.jta.TransactionManager;
      import com.arjuna.ats.jdbc.common.jdbcPropertyManager.*;
      import com.arjuna.ats.jdbc.TransactionalDriver.*;
      
      public class SampleTranscation {
      
       public static void main(String are[]){
      
       Properties p = System.getProperties();
       p.put("jdbc.drivers", "oracle.jdbc.driver.OracleDriver");
       System.setProperties(p);
       try
       {
       DriverManager.registerDriver(new com.arjuna.ats.jdbc.TransactionalDriver());
       }
       catch (Exception e) {
       e.printStackTrace();
       System.exit(0);
       }
      
       Connection conn = null;
       Connection conn2 = null;
       Statement stmtTrg = null;
       Statement stmtx = null;
       ResultSet rs = null;
       String sourceURL ="jdbc:oracle:thin:@source_machine:1521:ascarc4";
       String targetURL ="jdbc:oracle:thin:@target_machine:1521:ascarc3";
       Properties dbProperties = new Properties();
       try
       {
      
       System.out.println("\nCreating connection to database: "+sourceURL);
       dbProperties.put(TransactionalDriver.userName, "username_test");
       dbProperties.put(TransactionalDriver.password, "password_test");
       dbProperties.put(TransactionalDriver.dynamicClass,"com.arjuna.ats.internal.jdbc.drivers.oracle_8_1_6");
      
       conn = DriverManager.getConnection(sourceURL, dbProperties);
       conn2 = DriverManager.getConnection(targetURL, dbProperties);
      
       }catch(Exception exp){
       exp.printStackTrace();
       }
       System.out.println(" ---- the Source connection: "+ conn);
       System.out.println(" ---- the target connection: "+ conn2);
      
       try {
       System.out.println("Starting top-level transaction.");
       UserTransaction.userTransaction().begin();
      
       stmtx = conn.createStatement();
       rs = stmtx.executeQuery("SELECT * FROM AAA");
       while(rs.next()) {
       int number = rs.getInt(1);
      
       stmtTrg =conn2.createStatement();
       System.out.println(stmtTrg.executeUpdate("INSERT INTO AAA (EID) VALUES('"+number+"')"));
      
      
       }
       UserTransaction.userTransaction().commit();
      
       } catch(Exception expo){
       expo.printStackTrace();
       try {
       UserTransaction.userTransaction().rollback();
       } catch(Exception exp) {
       exp.printStackTrace();
       }
       }
      
      
      
       }
      }