10 Replies Latest reply on Nov 3, 2006 2:41 PM by marklittle

    Help, The JTA doesn't work!

    w19995

      I'm now testing the example: JDBCTest in Chapter 6 of JBoss JTA Programmers Guide. But it doesn't work and no any Exception throws. I use Oracle 8.1.7 and JDK 1.5.
      Does anyone can help me? Thanks.
      The source code:

      package demo;
      
      import java.sql.*;
      import java.util.*;
      
      import com.arjuna.ats.jdbc.*;
      
      public class JDBCTest {
       public static void main(String[] args) {
       /*
       * Register the driver via the system properties variable
       * "jdbc.drivers"
       */
       Properties p = System.getProperties();
       p.put("jdbc.drivers", "oracle.jdbc.driver.OracleDriver");
       System.setProperties(p);
       /*
       * Now register the JBossJTA 2.x transactional driver.
       */
       try {
       DriverManager.registerDriver(new
       com.arjuna.ats.jdbc.
       TransactionalDriver());
       } catch (Exception e) {
       e.printStackTrace();
       System.exit(0);
       }
       Connection conn = null;
       Connection conn2 = null;
       Statement stmt = null; // non-tx statement
       Statement stmtx = null; // will be a tx-statement
       Properties dbProperties = new Properties();
       String url = "jdbc:oracle:thin:@172.21.172.204:1521:inms05";
       try {
       System.out.println("\nCreating connection to database: " + url);
       dbProperties.put(TransactionalDriver.userName, "upm30415");
       dbProperties.put(TransactionalDriver.password, "upm30415");
       dbProperties.put(TransactionalDriver.dynamicClass,
       "com.arjuna.ats.internal.jdbc.drivers.oracle_8_1_6");
       conn = DriverManager.getConnection(url, dbProperties);
       conn2 = DriverManager.getConnection(url, dbProperties);
       stmt = conn.createStatement(); // non-tx statement
       try {
       stmt.executeUpdate("DROP TABLE test_table");
       stmt.executeUpdate("DROP TABLE test_table2");
       } catch (Exception e) {
      // assume not in database.
       }
       try {
       stmt.executeUpdate(
       "CREATE TABLE test_table (a INTEGER,b INTEGER)");
       stmt.executeUpdate(
       "CREATE TABLE test_table2 (a INTEGER,b INTEGER)");
       } catch (Exception e) {
       }
       try {
       System.out.println("Starting top-level transaction.");
       com.arjuna.ats.jta.UserTransaction.userTransaction().begin();
       stmtx = conn.createStatement(); // will be a tx-statement
       System.out.println("\nAdding entries to table 1.");
       stmtx.executeUpdate(
       "INSERT INTO test_table (a, b) VALUES(1, 2)");
       ResultSet res1 = null;
       System.out.println("\nInspecting table 1.");
       res1 = stmtx.executeQuery("SELECT * FROM test_table");
       while (res1.next()) {
       System.out.println("Column 1: " + res1.getInt(1));
       System.out.println("Column 2: " + res1.getInt(2));
       }
       System.out.println("\nAdding entries to table 2.");
       stmtx.executeUpdate(
       "INSERT INTO test_table2 (a, b) VALUES(3, 4)");
       res1 = stmtx.executeQuery(
       "SELECT * FROM test_table2");
       System.out.println(
       "\nInspecting table 2.");
       while (res1.next()) {
       System.out.println("Column 1: " + res1.getInt(1));
       System.out.println("Column 2: " + res1.getInt(2));
       }
       System.out.print("\nNow attempting to rollback changes.");
       com.arjuna.ats.jta.UserTransaction.userTransaction().
       rollback();
       com.arjuna.ats.jta.UserTransaction.userTransaction().begin();
       stmtx = conn.createStatement();
       ResultSet res2 = null;
       System.out.println("\nNow checking state of table 1.");
       res2 = stmtx.executeQuery("SELECT * FROM test_table");
       while (res2.next()) {
       System.out.println("Column 1: " + res2.getInt(1));
       System.out.println("Column 2: " + res2.getInt(2));
       }
       System.out.println("\nNow checking state of table 2.");
       stmtx = conn.createStatement();
       res2 = stmtx.executeQuery("SELECT * FROM test_table2");
       while (res2.next()) {
       System.out.println("Column 1: " + res2.getInt(1));
       System.out.println("Column 2: " + res2.getInt(2));
       }
       com.arjuna.ats.jta.UserTransaction.userTransaction().commit();
       } catch (Exception ex) {
       ex.printStackTrace();
       System.exit(0);
       }
       } catch (Exception sysEx) {
       sysEx.printStackTrace();
       System.exit(0);
       }
       }
      }


        • 1. Re: Help, The JTA doesn't work!
          kconner

           

          But it doesn't work and no any Exception throws

          You need to be a bit more explicit than this. Why do you think it doesn't work? What are you seeing?

          • 2. Re: Help, The JTA doesn't work!
            w19995

            Hi, Kevin:

            After executes

            com.arjuna.ats.jta.UserTransaction.userTransaction().begin();
             stmtx = conn.createStatement(); // will be a tx-statement
             System.out.println("\nAdding entries to table 1.");
             stmtx.executeUpdate(
             "INSERT INTO test_table (a, b) VALUES(1, 2)");
             System.out.println("\nAdding entries to table 2.");
             stmtx.executeUpdate(
             "INSERT INTO test_table2 (a, b) VALUES(3, 4)");
             System.out.print("\nNow attempting to rollback changes.");
             com.arjuna.ats.jta.UserTransaction.userTransaction().
             rollback();


            The transaction should be rollback, but it doesn't. The data have been inserted into DB. I'm very confused.
            Can you give me some idea?

            thanks,

            "Kevin.Conner@jboss.com" wrote:
            But it doesn't work and no any Exception throws

            You need to be a bit more explicit than this. Why do you think it doesn't work? What are you seeing?


            • 3. Re: Help, The JTA doesn't work!
              marklittle

              Can you include the output here from the run (all of the print statements)?

              • 4. Re: Help, The JTA doesn't work!
                w19995

                Hi, Mark:

                The output is:

                Creating connection to database: jdbc:oracle:thin:@172.21.172.204:1521:inms05
                Starting top-level transaction.
                
                Adding entries to table 1.
                
                Inspecting table 1.
                Column 1: 1
                Column 2: 2
                
                Adding entries to table 2.
                
                Inspecting table 2.
                Column 1: 3
                Column 2: 4
                
                Now attempting to rollback changes.
                Now checking state of table 1.
                Column 1: 1
                Column 2: 2
                
                Now checking state of table 2.
                Column 1: 3
                Column 2: 4




                "mark.little@jboss.com" wrote:
                Can you include the output here from the run (all of the print statements)?


                • 5. Re: Help, The JTA doesn't work!
                  marklittle

                  I should have noticed this before ...

                  String url = "jdbc:oracle:thin:@172.21.172.204:1521:inms05";


                  You need to include the fact that you want to use the transactional JDBC driver when running stand-alone. What this URL currently means is that you'll be using the normal Oracle JDBC driver, which will make all work on the connections independent transactions, not controlled by the JBossTS transactions you've also started.

                  To fix this, try changing it to:

                  String url = "jdbc:arjuna:oracle:thin:@172.21.172.204:1521:inms05";

                  I'll make sure the manual is updated in the next release to point this out.

                  • 6. Re: Help, The JTA doesn't work!
                    w19995

                    I have modified it as your comments, but exception throws.
                    The "com.arjuna.ats.internal.jdbc.drivers.oracle_8_1_6" is not found. I have searched the whole JTS/JTA package, no such class exists.
                    Can you help to solve it? thanks.

                    java.lang.ClassNotFoundException: com.arjuna.ats.internal.jdbc.drivers.oracle_8_1_6
                     at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                     at java.security.AccessController.doPrivileged(Native Method)
                     at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
                     at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                     at com.arjuna.ats.internal.jdbc.DirectRecoverableConnection.createConnection(DirectRecoverableConnection.java:391)
                    Creating connection to database: jdbc:arjuna:oracle:thin:@172.21.172.204:1521:inms05
                    
                     at com.arjuna.ats.internal.jdbc.DirectRecoverableConnection.getConnection(DirectRecoverableConnection.java:301)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.getConnection(ConnectionImple.java:584)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.registerDatabase(ConnectionImple.java:668)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.createStatement(ConnectionImple.java:161)
                     at demo.JDBCTest.main(JDBCTest.java:42)
                    java.sql.SQLException: java.lang.ClassNotFoundException: com.arjuna.ats.internal.jdbc.drivers.oracle_8_1_6
                     at com.arjuna.ats.internal.jdbc.DirectRecoverableConnection.createConnection(DirectRecoverableConnection.java:423)
                     at com.arjuna.ats.internal.jdbc.DirectRecoverableConnection.getConnection(DirectRecoverableConnection.java:301)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.getConnection(ConnectionImple.java:584)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.registerDatabase(ConnectionImple.java:668)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.createStatement(ConnectionImple.java:161)
                     at demo.JDBCTest.main(JDBCTest.java:42)
                    java.sql.SQLException: java.sql.SQLException: java.lang.ClassNotFoundException: com.arjuna.ats.internal.jdbc.drivers.oracle_8_1_6
                     at com.arjuna.ats.internal.jdbc.DirectRecoverableConnection.getConnection(DirectRecoverableConnection.java:311)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.getConnection(ConnectionImple.java:584)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.registerDatabase(ConnectionImple.java:668)
                     at com.arjuna.ats.internal.jdbc.ConnectionImple.createStatement(ConnectionImple.java:161)
                     at demo.JDBCTest.main(JDBCTest.java:42)


                    String url = "jdbc:arjuna:oracle:thin:@172.21.172.204:1521:inms05";


                    • 7. Re: Help, The JTA doesn't work!
                      marklittle

                      OK, so now we know you're trying to use the transactional driver :-)

                      We removed the Oracle 8 support via the direct method a while back. The recommended way of accessing the drivers (for any DB) is via JNDI. If you check the manual, you should find sufficient information to do this.

                      We'll update the example in the manual for the next release.

                      • 8. Re: Help, The JTA doesn't work!

                        Mark, I Have the same problem.
                        Do you have the updated exemple? When the "new" version of the manual come?

                        Thanks.

                        • 9. Re: Help, The JTA doesn't work!
                          ghosh99

                           

                          "mark.little@jboss.com" wrote:
                          OK, so now we know you're trying to use the transactional driver :-)

                          We removed the Oracle 8 support via the direct method a while back. The recommended way of accessing the drivers (for any DB) is via JNDI. If you check the manual, you should find sufficient information to do this.

                          We'll update the example in the manual for the next release.



                          JNDI lookup in standalone JbossTS also doesn't work. You have no choice but to integrate JBoss with JbossTS and use it. Seems like the standalone TS is broken unless someone posts an example here on how to use it !

                          • 10. Re: Help, The JTA doesn't work!
                            marklittle

                             

                            "ghosh99" wrote:
                            "mark.little@jboss.com" wrote:
                            OK, so now we know you're trying to use the transactional driver :-)

                            We removed the Oracle 8 support via the direct method a while back. The recommended way of accessing the drivers (for any DB) is via JNDI. If you check the manual, you should find sufficient information to do this.

                            We'll update the example in the manual for the next release.



                            JNDI lookup in standalone JbossTS also doesn't work.


                            The stand-alone TS doesn't ship with a JNDI implementation. You'd have to provide your own, obviously. But apart from that, why do you think it doesn't work?


                            You have no choice but to integrate JBoss with JbossTS and use it. Seems like the standalone TS is broken unless someone posts an example here on how to use it !


                            Until you post something that indicates to the contrary, we have to assume it works since most of our QA tests for JDBC use JNDI and run TS in stand-alone mode successfully. There are a lot of tests!