4 Replies Latest reply on Mar 3, 2004 3:11 AM by milowe

    Why i cannot lookup datasource from standalone application

    ipozeng

      Hi,friends
      I can use the datasource from entity bean CoffeesBean but i cannot lookup it from an standaline application:"SQLServerPool not bound"!
      By visiting 8082 port i get the following result:
      java:comp namespace of the CoffeesBean bean:
      +- env (class: org.jnp.interfaces.NamingContext)
      | +- jdbc (class: org.jnp.interfaces.NamingContext)
      | | +- SQLServerPool[link -> java:/DefaultDS] (class: javax.naming.LinkRef)

      java: Namespace
      +- jaas (class: javax.naming.Context)
      +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
      +- JmsXA (class: org.jboss.jms.ra.JmsConnectionFactoryImpl)
      +- MinervaSharedLocalCMFactory (class: org.jboss.pool.connector.jboss.MinervaSharedLocalCMFactory)
      +- DefaultDS (class: org.jboss.pool.jdbc.xa.XAPoolDataSource)
      +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
      +- MinervaXACMFactory (class: org.jboss.pool.connector.jboss.MinervaXACMFactory)
      +- TransactionManager (class: org.jboss.tm.TxManager)
      +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
      +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
      +- DefaultJMSProvider (class: org.jboss.jms.jndi.JBossMQProvider)
      +- SQLServerPool (class: org.jboss.pool.jdbc.xa.XAPoolDataSource)
      +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
      ......
      The bean can get the DataSource by using:
      InitialContext initCtx = new InitialContext();
      DataSource ds = (javax.sql.DataSource) initCtx.lookup("java:/SQLServerPool");
      The ejb-jar.xml:
      ......
      <resource-ref>
      <res-ref-name>jdbc/SQLServerPool</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      ......
      The jboss.xml:
      <reference-descriptor>
      <resource-description>
      <res-ref-name>jdbc/SQLServerPool</res-ref-name>
      <jndi-name>java:/SQLServerPool</jndi-name>
      </resource-description>
      </reference-descriptor>

      However the following code didnot work :(
      ......
      Properties h = new Properties();
      h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      h.put(Context.PROVIDER_URL,"localhost:1099");

      InitialContex initCtx = new InitialContext(h);
      System.out.println("got context");

      javax.sql.DataSource ds = (javax.sql.DataSource) initCtx.lookup("java:/SQLServerPool");
      System.out.println("got datasource");
      ......
      After printing "got context" it reports "SQLServerPool not bound" !

      I know i can define JNDI name in jboss but how about the standalone application?
      I have changed "java:/SQLServerPool" to "java:comp/env/jdbc/SQLServerPool" and "java:SQLServerPool" as the JNDIView outputs But all is the same :(

      Please help me out!

      Best Regards!