7 Replies Latest reply on Aug 7, 2006 9:09 AM by djhititup

    Complicated DataSouce and JNDI javax.naming.NamingException:

    djhititup

      My oracle-ds.xml is:

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

      <!-- ===================================================================== -->
      <!-- -->
      <!-- JBoss Server Configuration -->
      <!-- -->
      <!-- ===================================================================== -->

      <!-- $Id: oracle-ds.xml,v 1.6 2004/09/15 14:37:40 loubyansky Exp $ -->
      <!-- ==================================================================== -->
      <!-- Datasource config for Oracle originally from Steven Coy -->
      <!-- ==================================================================== -->



      <local-tx-datasource>
      <jndi-name>DCDEV</jndi-name>
      <!--
      Here are a couple of the possible OCI configurations.
      For more information, see http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96654/toc.htm

      <connection-url>jdbc:oracle:oci:@youroracle-tns-name</connection-url>
      or
      <connection-url>jdbc:oracle:oci:@(description=(address=(host=youroraclehost)(protocol=tcp)(port=1521))(connect_data=(SERVICE_NAME=yourservicename)))</connection-url>

      Clearly, its better to have TNS set up properly.
      -->
      <connection-url>jdbc:oracle:thin:@d2.corp.company.net:1521:DCDEV</connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>test</user-name>
      test

      <!--pooling parameters-->
      <min-pool-size>10</min-pool-size>
      <max-pool-size>30</max-pool-size>

      <!-- This element specifies the maximum time in milliseconds to block while waiting for a connection before throwing an exception. -->
      <blocking-timeout-millis>5000</blocking-timeout-millis>
      <!-- This element specifies the maximum time in minutes a connection may be idle before being closed. -->
      <idle-timeout-minutes>15</idle-timeout-minutes>

      <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
      <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
      <!-- Checks the Oracle error codes and messages for fatal errors -->
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
      <!-- sql to call when connection is created
      <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->

      <!-- sql to call on an existing pooled connection when it is obtained from pool - the OracleValidConnectionChecker is prefered
      <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

      <!-- This element specifies the number of prepared statements per connection in an LRU cache, which is keyed by the SQL query. Setting this to zero disables the cache. -->
      <prepared-statement-cache-size>15</prepared-statement-cache-size>

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

      <type-mapping>Oracle10i</type-mapping>

      </local-tx-datasource>




      My WEB-INF/web.xml is:

      <?xml version="1.0" encoding="ISO-8859-1"?>

      <web-app version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd">

      <!-- The Welcome File List -->
      <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>

      <resource-ref>
      Data Compilation DataSource
      <res-ref-name>DCDEV</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      </web-app>


      My WEB-INF/jboss-web.xml is:

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-web>
      <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
      <security-domain>java:/jaas/jmx-console</Dsecurity-domain>
      -->

      <reference-ref>
      <res-ref-name>DCDEV</res-ref-name>
      <jndi-name>java:/DCDEV</jndi-name>
      </reference-ref>

      </jboss-web>


      My question is why am I getting the following exception when jboss 4.0.4 is restarted or when I redeploy the application:

      org.jboss.deployment.DeploymentException: Error during deploy; - nested throwable: (javax.naming.NamingException: resource-ref: DCDEV has no valid JNDI binding. Check the jboss-web/resource-ref.)

      NOTE: The application is an exploded(unpacked) format. Not sure if i'm using the correct technical wording.

        • 1. Re: Complicated DataSouce and JNDI javax.naming.NamingExcept
          jaikiran

           

          <reference-ref>
          <res-ref-name>DCDEV</res-ref-name>
          <jndi-name>java:/DCDEV</jndi-name>
          </reference-ref>


          Is this a typo? If not, it should be:

          <resource-ref>
          <res-ref-name>DCDEV</res-ref-name>
          <jndi-name>java:/DCDEV</jndi-name>
          </resource-ref>




          • 2. Re: Complicated DataSouce and JNDI javax.naming.NamingExcept
            sachst

            Have you resolved this issue. I am having this same issue...

            • 3. Re: Complicated DataSouce and JNDI javax.naming.NamingExcept
              djhititup

              Thank you so much for catching that tag name problem; however the issue still remains. My code below still doesn't work.

              out.println("<H1>VERSION 2 w/ DataSource of DCPROD</H1>");
              Connection con2 = null;
              try {
              InitialContext context = new InitialContext(null);
              DataSource source = (DataSource)context.lookup("DCDEV"); // DOES NOT WORK
              //DataSource source = (DataSource)context.lookup("java:/DCDEV"); // DOES WORK
              con2 = source.getConnection();
              out.println("DONE!");
              } catch (Exception ex) {
              out.println("NO SUCCESS BECAUSE " + ex.getMessage() + "");
              //ex.printStackTrace(new PrintWriter(out));
              } finally {
              if (con2 != null) {
              con2.close();
              out.println("AND WE CLOSED IT!");
              }
              }

              • 4. Re: Complicated DataSouce and JNDI javax.naming.NamingExcept
                jaikiran

                 

                DataSource source = (DataSource)context.lookup("DCDEV"); // DOES NOT WORK


                The reason why this wont work is because, by default the datasources are bound in the java: namespace. If you want it to be bound in the global namespace then add the following statement to your ds configuration file(i.e. oracle-ds.xml)

                <local-tx-datasource>
                 <jndi-name>DCDEV</jndi-name>
                 <use-java-context>false</use-java-context>
                 ......
                 <!-- All your other stuff -->
                
                </local-tx-datasource>





                • 5. Re: Complicated DataSouce and JNDI javax.naming.NamingExcept
                  djhititup

                  Correct me if I'm wrong but isn't JBoss to bound the datasource to java:/ and then within your application using the web.xml and jboss-web.xml you bound it to a global reference within your application? If this is so why would i use that setting to bound it to a global reference from within JBoss when I only want a global reference from within my application?

                  • 6. Re: Complicated DataSouce and JNDI javax.naming.NamingExcept
                    jaikiran

                     

                    Correct me if I'm wrong but isn't JBoss to bound the datasource to java:/ and then within your application using the web.xml and jboss-web.xml you bound it to a global reference within your application


                    Are you talking about the resource-ref thing in web.xml and jboss-web.xml? If yes, then thats not the way it works. When you specify a resource-ref, you are binding the resource to the *application's java:comp/env jndi namespace* and *NOT* the global jndi namespace



                    • 7. Re: Complicated DataSouce and JNDI javax.naming.NamingExcept
                      djhititup

                      Thank you for the information. If you feel froggy I have more forum post. :D