0 Replies Latest reply on Dec 4, 2003 10:53 PM by leonkwan

    Java Transaction

    leonkwan Newbie

      I have made a servlet calling some java bean (not EJB) which process some database queries, insert and update. However, I would like them to be in an atomic transaction.

      I have tried to use setautocommit which fails because I use the connection pool of JBoss. So I think maybe I need to use JTA inside the servlet. So I try this:

      Properties prop = new Properties();
      prop.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      prop.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      prop.put("java.naming.provider.url", "localhost:1099");

      InitialContext ctx = new InitialContext(prop);
      utx = (UserTransaction) ctx.lookup("UserTransaction");


      if (myObj.save())

      where myObj.save() contains some coding to insert, update and select the database.

      However, it seems this does not work coz I deliberately return error in one of the update statement that I found the db is not rollback.

      Since I am new to JTA and also JBoss, I do not know whether my concept is correct or not. Or is there any website for me to get some sample code and know more about these?