4 Replies Latest reply on Dec 19, 2006 2:21 AM by augustfox

    jndi reference problem(urgent)?

    augustfox

      My environment is myeclipse4.1.1+jboss4.0.1sp1+DB28.2.
      When I wanna get a database connection,i meet with a problem,the error as follows:
      14:38:06,343 INFO [STDOUT] javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: jdbc not bound]
      14:38:06,343 INFO [STDOUT] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:999)
      14:38:06,343 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:629)
      14:38:06,343 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:658)
      14:38:06,343 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:520)
      14:38:06,343 INFO [STDOUT] at javax.naming.InitialContext.lookup(InitialContext.java:347)

      My code like this:
      Context context = new InitialContext();
      return (DataSource) context.lookup("java:comp/env/jdbc/test");

      I can get connecton via context.lookup("java:jdbc/test"),
      but i still want to know why context.lookup("java:comp/env/jdbc/test") not works?
      I want to get your help eagerly!


      my db2-ds.xml:
      <local-tx-datasource>
      <jndi-name>jdbc/test</jndi-name>
      <connection-url>jdbc:db2:tempdb</connection-url>
      <driver-class>COM.ibm.db2.jdbc.app.DB2Driver</driver-class>
      <user-name>test</user-name>
      test
      <min-pool-size>5</min-pool-size>
      <max-pool-size>20</max-pool-size>


      <type-mapping>DB2</type-mapping>

      </local-tx-datasource>

      my web.xml:
      <resource-ref>
      <res-ref-name>jdbc/test</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>

      my jboss-web.xml:
      <resource-ref>
      <res-ref-name>jdbc/test</res-ref-name>
      <jndi-name>jdbc/test</jndi-name>
      </resource-ref>

      I also tried resource-env-ref in my web.xml and jboss-web.xml,it still not works.
      thanks a lot!

        • 1. Re: jndi reference problem(urgent)?
          peterj

          Try changing your jboss.xml to:

          <resource-ref>
          <res-ref-name>jdbc/test</res-ref-name>
          <jndi-name>comp/env/jdbc/test</jndi-name>
          </resource-ref>

          or was it

          <resource-ref>
          <res-ref-name>comp/env/jdbc/test</res-ref-name>
          <jndi-name>jdbc/test</jndi-name>
          </resource-ref>

          One of those should work.

          • 2. Re: jndi reference problem(urgent)?
            augustfox

            thanks PeterJ!
            But both still failed.
            when try
            <resource-ref>
            <res-ref-name>jdbc/test</res-ref-name>
            <jndi-name>comp/env/jdbc/test</jndi-name>
            </resource-ref>
            the error is:
            javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: comp not bound]

            and when try
            <resource-ref>
            <res-ref-name>comp/env/jdbc/test</res-ref-name>
            <jndi-name>jdbc/test</jndi-name>
            </resource-ref>
            the error is:
            javax.naming.NameNotFoundException: test not bound

            • 3. Re: jndi reference problem(urgent)?
              peterj

              Finally figured it out. Change jboss-web.xml to:

              <resource-ref>
               <res-ref-name>jdbc/test</res-ref-name>
               <jndi-name>java:jdbc/test</jndi-name>
              </resource-ref>


              • 4. Re: jndi reference problem(urgent)?
                augustfox

                Thanks PeterJ very much!

                Now it works well.
                ^_^