2 Replies Latest reply on Nov 27, 2002 10:18 PM by dokomesiter

    jndi lookup

      Hello,
      I have a utility class that my EJB's use to obtain a db connection from a pool. I currently have it working using:
      Context initctx = new InitialContext();
      javax.sql.DataSource ds = (javax.sql.DataSource)initctx.lookup("java:/MyDS");

      What do I have to do in order to be able to look it up as
      Context initctx = new InitialContext();
      javax.sql.DataSource ds = (javax.sql.DataSource)initctx.lookup("java:comp/env/jdbc/MyDS");

      In my jboss.xml I have:
      <resource-managers>
      <resource-manager>
      <res-name>MyDS</res-name>
      <res-jndi-name>jdbc/MyDS</res-jndi-name>
      </resource-manager>
      </resource-managers>
      But this does not do the trick.

      Thanks.

        • 1. Re: jndi lookup
          lucvu

          I know this is a little late to reply, but this might help whoever is reading this.

          What you need to do is this:

          <resource-managers>
          <resource-manager>
          <res-name>jdbc/MyDS</res-name>
          <res-jndi-name>java:/MyDS</res-jndi-name>
          </resource-manager>
          </resource-managers>

          • 2. Re: jndi lookup
            dokomesiter

            Nope, doesn't seem to work, only the "java:/" works, trying to map to
            the more portable "java:comp/env..." as you suggest fails, either not
            finding the name in the context, or, even worse, apparently using the
            wrong driver (maybe one of the developers would be interested in that)

            C:\eclipse\workspace\Converter>ant run-junit
            run-junit-jboss-client:
            [junit] driverName=HSQL Database Engine Driver
            [junit] OK (3 tests)

            run-junit-sun-client:
            [junit] .driverName=Mark Matthews' MySQL Driver
            [junit] OK (3 tests)


            And the few relevant lines in the files

            jboss.xml
            <resource-managers>
            <resource-manager>
            <res-name>jdbc/ODCSDS</res-name>
            <res-jndi-name>java:/ODCSDS</res-jndi-name>
            </resource-manager>
            </resource-managers>

            ejb-jar.xml
            <resource-ref>
            <res-ref-name>jdbc/ODCSDS</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>

            MyBean.java
            DataSource dataSource = (DataSource) ic.lookup("java:comp/env/jdbc/ODCSDS");
            return dataSource.getConnection().getMetaData().getDriverName();

            mysql-service.xml
            ODCSDS