1 Reply Latest reply on Jun 26, 2003 9:42 AM by Jon Barnett

    two jboss servers,how to configure the two datasources?

    xiaoyi Newbie

      Now i start up a transaction on jboss server1,lookup the db2 ,and then i call an ejb that is on the jboss server2 ,the ejb will lookup the oracle db.
      Must i configure the db2-ds.xml as xa interface.the primary codes are:
      UserTransaction ut = sessionContext.getUserTransaction();
      ut.begin();
      System.out.println("transaction begin");
      DataSource ds = (DataSource)new InitialContext ().lookup ("java:/DB2DS");
      System.out.println("db2ds is bound");
      java.sql.Connection con = ds.getConnection ();
      System.out.println("begin to connect to db2");
      Statement s = con.prepareStatement("select * from protonaccount");

      ResultSet rs=s.executeQuery("select * from protonaccount");
      System.out.println("select begin");
      if(rs.next()){
      name=rs.getString("name");

      System.out.println(name);

      }

      s.close();
      System.out.println("state is closed");
      con.close();
      System.out.println("connect is closed");
      System.out.println("begin to do cmt");
      Hashtable env = new Hashtable();
      env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      env.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
      env.put("java.naming.provider.url", "10.51.42.16");
      InitialContext ctx = new InitialContext(env);
      Object ob = ctx.lookup("cmtbean");
      cmtbeanHome home = (cmtbeanHome)PortableRemoteObject.narrow(ob, cmtbeanHome.class);
      cmtbeanRemote bean = home.create();
      bean.test();
      //ProtonAccountHome home = (ProtonAccountHome)PortableRemoteObject.narrow(ob,ProtonAccountHome.class);
      // ProtonAccount bean = home.creat();
      //bean.getBalance();
      ut.rollback();
      System.out.print("bmt done");
      but the wrong message are :16:52:13,487 INFO [TxConnectionManager] Started
      16:52:13,487 INFO [MainDeployer] Deployed package: file:/E:/jboss4/jboss-head/b
      uild/output/jboss-4.0.0alpha/server/default/deploy/db2-ds.xml
      16:52:15,690 INFO [STDOUT] transaction begin
      16:52:15,690 INFO [STDOUT] db2ds is bound
      16:52:15,920 INFO [STDOUT] begin to connect to db2
      16:52:15,920 INFO [STDOUT] select begin
      16:52:15,920 INFO [STDOUT] exception in bmtbean
      16:52:15,920 INFO [CachedConnectionManager] Successfully closed a connection fo
      r you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConne
      ction@1553743
      java.lang.Exception: Stack Trace
      at org.jboss.resource.connectionmanager.CachedConnectionManager.closeAll
      (CachedConnectionManager.java:342)
      at org.jboss.resource.connectionmanager.CachedConnectionManager.popMetaA
      wareObject(CachedConnectionManager.java:184)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      ke(CachedConnectionInterceptor.java:120)
      at org.jboss.ejb.plugins.TxSupport.invokeInNoTx(TxSupport.java:181)
      at org.jboss.ejb.plugins.TxSupport$StatelessBMT.invokeInNoTxBMT(TxSuppor
      t.java:886)
      at org.jboss.ejb.plugins.TxSupport$StatelessBMT.serverInvoke(TxSupport.j
      ava:878)
      at org.jboss.ejb.plugins.TxInterceptorCMT.internalInvoke(TxInterceptorCM
      T.java:101)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:5
      3)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
      elessSessionInstanceInterceptor.java:47)
      at org.jboss.security.RunAsSecurityInterceptor.invoke(RunAsSecurityInter
      ceptor.java:61)
      at org.jboss.security.RoleBasedAuthorizationInterceptor.invoke(RoleBased
      AuthorizationInterceptor.java:54)
      at org.jboss.security.AuthenticationInterceptor.invoke(AuthenticationInt
      erceptor.java:65)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:117)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFacto
      ryFinderInterceptor.java:102)
      at org.jboss.ejb.Container.invoke(Container.java:975)
      at org.jboss.ejb.Container.invoke(Container.java:1087)
      at org.jboss.mx.server.RawDynamicInvoker.invoke(RawDynamicInvoker.java:1
      43)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:544)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:90)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.jav
      a:89)
      at org.jboss.ejb.plugins.TxSupport$StatelessBMT.clientInvoke(TxSupport.j
      ava:849)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.
      java:129)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:8
      1)
      at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessi
      onInterceptor.java:110)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:84)
      at $Proxy54.test(Unknown Source)
      at org.apache.jsp.ds_jsp._jspService(ds_jsp.java:61)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
      .java:210)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
      95)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360
      )
      at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicati
      onHandler.java:294)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:5
      58)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
      at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplication
      Context.java:505)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
      at org.mortbay.http.HttpServer.service(HttpServer.java:861)
      at org.jboss.jetty.Jetty.service(Jetty.java:497)
      at org.mortbay.http.HttpConnection.service(HttpConnection.java:773)
      at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:935)
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:790)
      at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:
      201)
      at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
      at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:454)
      16:52:15,930 ERROR [TxSupport] Application error, UserTransaction not complete o
      n return of call to stateless session bean 1424214388
      16:52:15,930 WARN [jbossweb] WARNING: Exception for /remote/ds.jsp: java.rmi.Re
      moteException: Application error, UserTransaction not complete on return of call
      to stateless session bean 1424214388
      Who can tell me the reason?
      the db2-ds.xml is:

      <local-tx-datasource>
      <jndi-name>DB2DS</jndi-name>
      <connection-url>jdbc:db2:account</connection-url>
      <driver-class>COM.ibm.db2.jdbc.app.DB2Driver
      </driver-class>
      <user-name>db2</user-name>
      db2
      </local-tx-datasource>

      thanks!

        • 1. Re: two jboss servers,how to configure the two datasources?
          Jon Barnett Master

          In your code, you don't have a finally block to ensure that your connections close. Your rs.next() loop has a problem somewhere in it that causes an exception that you don't catch. Since you don't catch the exception, your bean method terminates while in the loop, bypassing your close() statements. This causes JBoss to generate warnings because you left the method without explicitly closing the pooled connection.

          Ensure that you properly try,catch,finally your database operations so that resources are properly cleaned up. That should at least get you to a stage that your code executes in some semblance of orderly behaviour.