Hi All,
How ao I lookup for the DataSource in JBoss? I created mysql-ds.xml and deployed on JBoss. When I start my JBoss I can see it getting bound as java:MasteringEJBPool. I am looking up for this DS like
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:MasteringEJBPool");
return ds.getConnection();
This works fine, but I am not able to understand how it is working?
Is it going though my ejb-jar.xml & jboss.xml? Looks like no!!, if it is not how is it looking on my localhost?
I would appreciate if someone can let me know how actually DS lookup works for EJBs on JBoss.
Kind Regards,
Gautham.
-
DataSource Lookup in JBoss (3 messages)
- Posted by: Gautham GV
- Posted on: November 10 2004 23:51 EST
Threaded Messages (3)
- well by Alon Agmon on November 11 2004 16:20 EST
- DataSource Lookup in JBoss by weiyue chen on March 06 2006 18:26 EST
- Re: DataSource Lookup in JBoss by BERDAI Adil on March 14 2007 09:43 EDT
-
well[ Go to top ]
- Posted by: Alon Agmon
- Posted on: November 11 2004 16:20 EST
- in response to Gautham GV
the 'java:/whatever' namespace is a namespace used by all the application server's components and only by them -
when u deploy a data source (xxx-ds.xml)
it is bound to the jndi name you gave him.
and when you do a "new InitialContext()" you are actually using a set of properties configuring
the jndi provider , classes etc e.g the jndi.properties file in the classpath(usually).
refer to jboss's docs - it is well explained there... -
DataSource Lookup in JBoss[ Go to top ]
- Posted by: weiyue chen
- Posted on: March 06 2006 18:26 EST
- in response to Gautham GV
Example for EJBs
jboss.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<secure>false</secure>
<enterprise-beans>
<session>
<ejb-name>gameBean</ejb-name>
<jndi-name>ejb/gameBean</jndi-name>
<clustered>false</clustered>
</session>
</enterprise-beans>
</jboss>
Java code:
ctx = new InitialContext();
gameBeanHome hm = PortableRemoteObject.narrow(ctx.lookup("ejb/gameBean"), gameBeanHome.class);
for DataSource
in xxx-ds.xml
<local-tx-datasource>
<jndi-name>OracleDS</jndi-name>
<connection-url>jdbc:oracle:thin:@10.1.1.205:1521:devdb</connection-url>
---
in java
ctx = new InitialContext();
ds = (javax.sql.DataSource) ctx.lookup("java:OracleDS"); -
Re: DataSource Lookup in JBoss[ Go to top ]
- Posted by: BERDAI Adil
- Posted on: March 14 2007 09:43 EDT
- in response to weiyue chen
I developped the same thing and finally I a WrappedDataSource instead of a javax.sql.DataSource..and when I make a ds.getConnection(), it throws an exception : org.jboss.util.NestedSQLException: Problem locating real ConnectionManager: jboss.jca:service=LocalTxCM,name=MyDS; - nested throwable: (java.lang.IllegalStateException: No 'jboss' MBeanServer found!); - nested throwable: (Problem locating real ConnectionManager: jboss.jca:service=LocalTxCM,name=MyDS; - nested throwable: (java.lang.IllegalStateException: No 'jboss' MBeanServer found!)) at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94) at com.solutions.auto.persistence.connection.DBManager.getConnection(DBManager.java:133) the following instruction gives : System.out.println(" " + dataSource.getClass().getName()); org.jboss.ressource.adapter.jdbc.WrappedDataSource and the next one gives : System.out.println("Got datasource: " + dataSource.getConnection().getClass().getName()); org.jboss.ressource.adapter.jdbc.WrappedConnection Any idea about how to retrive a Connection ? thx in advance