4 Replies Latest reply on Mar 10, 2004 5:14 AM by mlsreekanth

    CANNOT lookup on a datasource

    Xavier MOGHRABI Newbie


      I'm working on a program mixing EJB and object whose persistance is managed by DAO over JDBC.

      I'd like to use the JBoss' connection pool to manage the connection available. I thought that the best way is to look up for the datasource and after to get connection from it. However I didn't success to look up for the DS. I don't know why and I wrote a small code to determine all the jndi names. I ran the same code on JOnAS and I got the JNDI name of my DS.

      So I used as DataSource a RDBMS which is MaxDB 7.5.

      here's my connector file :

       <xa-datasource-property name="Url">jdbc:sapdb://</xa-datasource-property>
       <xa-datasource-property name="User">dba</xa-datasource-property>
       <xa-datasource-property name="Password">dba</xa-datasource-property>

      The connection is OK because I success to use CMP EJB and to persist data into the MaxDB.

      Then after I wrote a simple Test class to catch the Datasource :
      import java.util.Hashtable;
      import javax.ejb.CreateException;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingEnumeration;
      import javax.naming.NamingException;
      import javax.sql.DataSource;
      public class Test{
      static Context ctx = null;
      public static void main(String[]args) {
       Test prog = new Test();
       public Test(){
       try {
       ctx = getContext();
       catch (NamingException e) {
       try {
       NamingEnumeration enum = ctx.list("");
       while (enum.hasMore()) {
       catch (NamingException e) {
      // Next, lookup the DataSource
       try {
       DataSource ds = (DataSource) getContext().lookup("java:/MaxdbXADS");
       } catch (NamingException e) {
       System.out.println("DS Not found");
      private static InitialContext getContext() throws NamingException {
       Hashtable props = new Hashtable();
       props.put(InitialContext.PROVIDER_URL, "jnp://");
       InitialContext initialContext = new InitialContext(props);
       return initialContext;

      However I've the following result which proofs that i cannot connect on my Datasource. I find strange that when I display the list of Jndi names available there isn't my Datasource !

      HAILConnectionFactory: org.jboss.mq.SpyConnectionFactory
      HASessionState: org.jnp.interfaces.NamingContext
      jmx: org.jnp.interfaces.NamingContext
      OIL2XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      HTTPXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      ConnectionFactory: org.jboss.mq.SpyConnectionFactory
      clustering: org.jnp.interfaces.NamingContext
      UserTransactionSessionFactory: $Proxy10
      HTTPConnectionFactory: org.jboss.mq.SpyConnectionFactory
      ClientLocal: $Proxy44
      XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      invokers: org.jnp.interfaces.NamingContext
      UserTransaction: org.jboss.tm.usertx.client.ClientUserTransaction
      HAILXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      RMIXAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      UILXAConnectionFactory: javax.naming.LinkRef
      UIL2XAConnectionFactory: org.jboss.mq.SpyXAConnectionFactory
      HAPartition: org.jnp.interfaces.NamingContext
      queue: org.jnp.interfaces.NamingContext
      topic: org.jnp.interfaces.NamingContext
      console: org.jnp.interfaces.NamingContext
      UIL2ConnectionFactory: org.jboss.mq.SpyConnectionFactory
      UILConnectionFactory: javax.naming.LinkRef
      CommandeLocal: $Proxy45
      RMIConnectionFactory: org.jboss.mq.SpyConnectionFactory
      CtrlGererCommandeVenteFacadeBean: $Proxy50
      MaxIDLocal: $Proxy46
      OIL2ConnectionFactory: org.jboss.mq.SpyConnectionFactory
      UUIDKeyGeneratorFactory: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory
      DS not found

      Does anybody have an idea ?

      Xavier MOGHRABI

        • 1. Re: CANNOT lookup on a datasource
          Adrian Brock Master

          Correct in jboss-3.2 the datasources are not available outside the virtual machine.
          Although it is convenient, it does not scale and it is a potential security problem.
          There is code in jboss4 to do this, but I still wouldn't recommend it.


          • 2. Re: CANNOT lookup on a datasource
            Xavier MOGHRABI Newbie

            Thank you for your response but how can I get a connection to my DBMS for simple objets using Jboss Connection Pool ?

            Is it possible ?

            In fact I have objets which use JDBC and I want to use the connection as defined in jboss/deploy.

            Xavier MOGHRABI

            • 3. Re: CANNOT lookup on a datasource
              Juha Lindfors Master

              Deploy a server side component, like a SLSB, that talks to your datasource.

              • 4. Couldn't send messages to a message queue in JBOSS from a re
                mlsreekanth Newbie

                Hi all,

                I an trying to send message to a JBOSSMQ queue which is located in a system and the system was in internetwork. I am sending using the IP address and code was as follows,

                java.util.Hashtable JNDIParm = new java.util.Hashtable();
                JNDIParm.put(Context.PROVIDER_URL, "jnp://");

                JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                jndiContext = new InitialContext(JNDIParm);
                Queue queue = (Queue) jndiContext.lookup(destinationJndiName);
                QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup(connectionFactoryJndiName);
                queueConnection = queueConnectionFactory.createQueueConnection();
                queueSession = queueConnection.createQueueSession( false, Session.AUTO_ACKNOWLEDGE );
                queueSender = queueSession.createSender(queue);

                ObjectMessage message;


                This is giving the follwong error

                javax.naming.CommunicationException [Root exception is java.rmi.ConnectException: Connection refused to host:; nested exception is:
                java.net.ConnectException: Connection timed out: connect]
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:611)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
                at javax.naming.InitialContext.lookup(InitialContext.java:347)
                at MsgSender.sendMessage(MsgSender.java:77)
                at InternationalCaseSend$CaseSenderThread.run(InternationalCaseSend.java:301)
                Caused by: java.rmi.ConnectException: Connection refused to host:; nested exception is:
                java.net.ConnectException: Connection timed out: connect
                at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:567)
                at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
                at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
                at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:101)
                at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
                at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
                ... 4 more
                Caused by: java.net.ConnectException: Connection timed out: connect
                at java.net.PlainSocketImpl.socketConnect(Native Method)
                at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
                at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
                at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
                at java.net.Socket.connect(Socket.java:452)
                at java.net.Socket.connect(Socket.java:402)
                at java.net.Socket.(Socket.java:309)
                at java.net.Socket.(Socket.java:124)
                at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
                at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
                at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:562)

                Kindly, help me in this regard

                Thanks in advance