4 Replies Latest reply on Mar 11, 2003 3:22 PM by fubao

    JBoss3.0.4 Datasource lookup

    p661121

      Hi,

      i try to run a web application on JBoss 3.0.4 but the lookup of the
      DataSource failed with:
      javax.naming.NameNotFoundException: jdbc not bound

      the source lookup
      DataSource dataSource = (DataSource)
      initialContext.lookup("jdbc/JSC_PERFTEST_DS");

      (with
      DataSource dataSource = (DataSource)
      initialContext.lookup("java:/jdbc/JSC_PERFTEST_DS");
      the JBoss lookup work fine, but it isnt J2EE compliant and didn't work with
      WebSphere )

      The Datasource is bound in JBoss
      15:29:28,755 INFO [jdbc/JSC_PERFTEST_DS] Bound connection factory for
      resource adapter 'JBoss LocalTransaction JDBC Wrapper' to JNDI name
      'java:/jdbc/JSC_PERFTEST_DS'



      Part of my web.xml
      <resource-ref>
      Datasource fuer Performancetest
      <res-ref-name>jdbc/JSC_PERFTEST_DS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      My jboss-web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-web>
      <resource-ref>
      <res-ref-name>jdbc/JSC_PERFTEST_DS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/jdbc/JSC_PERFTEST_DS</jndi-name>
      </resource-ref>
      </jboss-web>

      Any idea whats wrong in this ??

        • 1. Re: JBoss3.0.4 Datasource lookup

          You should lookup from the private ENC java:comp/env/<jdbc/YourDSName> and map that to the in-VM java: name for the DS

          that is the J2EE compat. way to do it

          • 2. Re: JBoss3.0.4 Datasource lookup
            ctaggart

            I've been trying to bind a MySQL database connection for a couple of days now without any luck. I had a working Tomcat web application, and I'm trying to port it over to JBoss v3.0.6 with Jetty and I can't seem to bind/access the MySQL database connection.

            I used the example mysql-service.xml and changed all the name references to be jdbc/PeopleFinderDB, e.g.

            jdbc/PeopleFinderDB


            The server.log reports this when I deploy the mysql-service.xml mbean:

            2003-02-24 14:26:32,506 INFO [org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.jdbc/PeopleFinderDB] Bound connection factory for resource adapter 'JBoss LocalTransaction JDBC Wrapper' to JNDI name 'java:/jdbc/PeopleFinderDB'
            2003-02-24 14:26:32,516 INFO [org.jboss.resource.connectionmanager.LocalTxConnectionManager] Started
            2003-02-24 14:26:32,516 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/C:/java/jboss-3.0.6/server/default/deploy/mysql-service.xml

            My jboss-web.xml contains this:
            <resource-ref>
            <res-ref-name>jdbc/PeopleFinderDB</res-ref-name>
            <!--<jndi-name>java:/jdbc/PeopleFinderDB</jndi-name>-->
            <jndi-name>jdbc/PeopleFinderDB</jndi-name>
            </resource-ref>

            My web.xml contains this:
            <resource-ref>
            <res-ref-name>jdbc/PeopleFinderDB</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            </resource-ref>

            Then in a JSP page, I recursively print the context tree starting with the initial context and the datasource isn't listed.

            Please help!

            Thanks,
            Cameron

            • 3. Re: JBoss3.0.4 Datasource lookup
              joey75205

              I have a similar problem doing this with EJBs. For some reason, jBoss only binds the DefaultDS to my resource-ref rather than the ref I defined in the jboss.xml file. I have not been able to get an answer to my own post so I thought I'd piggy back here. Have you guys had any luck doing this in a web application?

              I can see the java:comp/env naming context in the JNDI view but it doesn't point to my deployed datasources.

              Thanks,

              Joey

              • 4. Re: JBoss3.0.4 Datasource lookup
                fubao

                You have to do the mapping in jboss.xml.

                To map your java:/yourDS to java:comp/env/jdbc/aDs, besides give <resource-ref> in your ejb-jar.xml as:

                <ejb-name>youEjb</ejb-name>
                ...
                <resource-ref>
                <res-ref-name>jdbc/aDs</res-ref-name>
                <res-type>javax.sql.DataSource</res-type>
                <res-auth>Container</res-auth>
                </resource-ref>


                In jboss.xml, you should give:

                <enterprise-beans>

                <ejb-name>yourEjb</ejb-name>
                <resource-ref>
                <res-ref-name>jdbc/aDs</res-ref-name>
                <jndi-name>java:/yoursDS</jndi-name>
                </resource-ref>

                </enterprise-beans>


                This way, you can lookup you DS by "java:comp/env/jdbc/aDs". It works fine for me.