CANNOT lookup on a datasource
moghrabi Feb 25, 2004 11:24 AMHello,
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 :
<datasources> <xa-datasource> <jndi-name>MaxdbXADS</jndi-name> <track-connection-by-tx>true</track-connection-by-tx> <xa-datasource-class>com.sap.dbtech.jdbcext.XADataSourceSapDB</xa-datasource-class> <xa-datasource-property name="Url">jdbc:sapdb://127.0.0.1/XM</xa-datasource-property> <xa-datasource-property name="User">dba</xa-datasource-property> <xa-datasource-property name="Password">dba</xa-datasource-property> </xa-datasource> </datasources>
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) { e.printStackTrace(); System.exit(2); } try { NamingEnumeration enum = ctx.list(""); while (enum.hasMore()) { System.out.println(enum.next()); } } catch (NamingException e) { e.printStackTrace(); } // Next, lookup the DataSource try { DataSource ds = (DataSource) getContext().lookup("java:/MaxdbXADS"); System.out.println(ds.toString()); } catch (NamingException e) { System.out.println("DS Not found"); } } private static InitialContext getContext() throws NamingException { Hashtable props = new Hashtable(); props.put( InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099"); 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