5 Replies Latest reply on May 3, 2011 5:46 AM by titang

    Unable to get managed connection for jdbc

    titang

      Hi everybody,

       

      I have been searching how to solve my problem but I can't find any solution. I am quite sure I must have forgotten something but I don't know what. So I guess I need some help unfortunaltely.

       

      So I am having the following exceptions when I try to deploy my application:

       

      ERROR [org.rhq.core.pc.inventory.InventoryManager] Call to getAvailablity() on ResourceComponent for Resource[id=-49, type=Service Binding Manager, key=ServiceBindingManager, name=Service Binding Manager, parent=JBoss AS 6 (default)] failed.: org.rhq.core.pc.inventory.TimeoutException: Call to [org.rhq.plugins.jbossas5.serviceBinding.ManagerComponent.getAvailability()] with args [] timed out. Invocation thread will be interrupted

       

      2011-04-28 18:09:01,309 ERROR [STDERR] (ResourceContainer.invoker.nonDaemon-1) org.jboss.util.NestedSQLException: Unable to get managed connection for jdbc/test; - nested throwable: (javax.resource.ResourceException: Unable to get managed connection for jdbc/test)

       

      I am focusing on the second error but the first one may be the cause of the SQL Exception. I could not find any information on the first exception and have absolutely no idea which part of my app raises this exception.

       

      The second error appears when I use this code:

       

      DataSource ds = (DataSource)((Context)(new InitialContext()).lookup("java:/comp/env")).lookup("jdbc/test");
      
      final Connection conn = ds.getConnection();
      

       

      In order to declare my data source (an Oracle 10g database), I used the following files:

       

      oracle-ds.xml:

       <datasources>
      
        <local-tx-datasource>
          <jndi-name>jdbc/test</jndi-name>
          <use-java-context>false</use-java-context>
          <connection-url>jdbc:oracle:thin:@test-oracle:1521:test</connection-url>
          <!--
      
              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.
           -->
          <min-pool-size>5</min-pool-size>
          <max-pool-size>100</max-pool-size>
      
          <driver-class>oracle.jdbc.OracleDriver</driver-class>
          <user-name>test</user-name>
          <password>test</password>
      
          <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
            <metadata>
               <type-mapping>Oracle9i</type-mapping>
            </metadata>
        </local-tx-datasource>
      
      </datasources>
      

       

      jboss-web.xml:

      <jboss-web>
      
        <!-- A security domain that restricts access
        <security-domain>java:/jaas/JBossWS</security-domain>
        -->
      
          <context-root>test</context-root>
      
          <resource-ref>
              <res-ref-name>jdbc/test</res-ref-name> 
              <!--res-type>javax.sql.DataSource</res-type-->
              <jndi-name>jdbc/test</jndi-name>      
          </resource-ref>
      </jboss-web>
      

       

      web.xml:

       

      <resource-ref>
              <description>Oracle data source</description>
              <res-ref-name>jdbc/test</res-ref-name>
              <res-type>javax.sql.DataSource</res-type>
              <res-auth>Container</res-auth>
              <res-sharing-scope>Unshareable</res-sharing-scope>
          </resource-ref>
      

      No other resources are declared. The oracle datasource is up in the admin-console.

       

      If you have any idea, thank you. If there are any informations lacking, tell me, I will add them as soon as possible. Thank you

        • 1. Unable to get managed connection for jdbc
          wdfink

          The datasource is normaly reachable under 'java:'

          You should use lookup("java:jdbc/test").

          But I'm not sure whether jdbc/test works, if not try jdbcTest to check it.

          • 2. Unable to get managed connection for jdbc
            titang

            I already tried that solution but I had the same error. I added <use-java-context>false</use-java-context> to use directly jdbc/test without java: but it may be wrong. I will try again tomorrow.

             

            The driver I use is ojdbc14.jar. If I replace lookup("jdbc/test") by lookup("jdbc/foo"), I get another exception (Naming Exception I think). Thanks for your answer

            • 3. Unable to get managed connection for jdbc
              wdfink

              I meant you should use a simple JNDI name without '/'.

               

              <jndi-name>MyJDBCTest</jndi-name>

              You should remove the 'use-java-context' element, I do not need it.

               

              this lookup should work:

              initialContext.lookup("java:MyJDBCTest");

               

              If you have problems please attach the error log message.

              Also I would recommend to use a newer ojdbc implementation, the ojdbc6.jar require a Java6 runtime environment.

               


              • 4. Re: Unable to get managed connection for jdbc
                titang

                I am still having the same problem. The datasource seems to be well set cause if I put a wrong jndi-name or if I have any error in my jboss-web.xml , the lookup code is not even executed.

                 

                I did not mention it but I am using jBoss 6. I tried to deploy my application on jBoss 5 and it worked. I had some execution problems but I was able access the database.

                 

                I also tried to use ojdbc5.jar, but it did not improve anything.

                 

                My main issue are in fact those exceptions:

                 

                ERROR org.rhq.core.pc.inventory.InventoryManager Call to getAvailablity() on ResourceComponent for Resource[id=-49, type=Service Binding Manager, key=ServiceBindingManager, name=Service Binding Manager, parent=JBoss AS 6 (default)] failed.: org.rhq.core.pc.inventory.TimeoutException: Call to org.rhq.plugins.jbossas5.serviceBinding.ManagerComponent.getAvailability() with args [] timed out. Invocation thread will be interrupted

                 

                I have no clue which part of my application is involved in these errors. And I don't know if it is related to the impossibility to get a connection to the datasource. How could I know which resource is raising this exception?

                 

                Thanks again.

                • 5. Unable to get managed connection for jdbc
                  titang

                  Finally I was able to deploy my application without using the admin console. When copying the war file in the deploy folder, I have no errors. I am still having the same problems when I try to deploy the application using the admin console page.

                   

                  So problem solved? Not really but I can finally use my app. I am still wondering what is the problem with the inventory manager. Moreover, why is a jBoss 5 class used in jBoss 6?

                   

                  Thanks for the answers.