DataSource Lookup in JBoss


EJB programming & troubleshooting: DataSource Lookup in JBoss

  1. DataSource Lookup in JBoss (3 messages)

    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,

    Threaded Messages (3)

  2. well[ Go to top ]

    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 file in the classpath(usually).

    refer to jboss's docs - it is well explained there...
  3. DataSource Lookup in JBoss[ Go to top ]

    Example for EJBs
    <?xml version="1.0" encoding="UTF-8"?>


    Java code:
    ctx = new InitialContext();
            gameBeanHome hm = PortableRemoteObject.narrow(ctx.lookup("ejb/gameBean"), gameBeanHome.class);

    for DataSource
    in xxx-ds.xml

    in java
    ctx = new InitialContext();
    ds = (javax.sql.DataSource) ctx.lookup("java:OracleDS");
  4. Re: DataSource Lookup in JBoss[ Go to top ]

    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( at 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