4 Replies Latest reply on Jul 8, 2003 5:05 AM by imcshane

    Using JDBC from within a Resource Adapter - some questions

    imcshane

      Hi,

      I've written a resource adapter and have successfully been using it with various JBoss 3.0.x versions for quite a while now. At the moment I'm using 3.0.7 (with tomcat).

      Recently I've added some JDBC to my managed connections. I'm accessing the database via a ConnectionFactory for a postgres db.

      This has caused problems because I get the following error message when "cleanup()" is called on my managed connection:
      "Successfully closed a connection for you. Please close them yourself:"
      The message is referring to my JDBC connection handle stored in my managed connection.

      Why is it necessary to close jdbc connection handles at this point ? I can understand it being necessary to force the connection closure for a destroy() but am unsure of the reasons for doing it on a cleanup().

      I was hoping that I could keep connection handles open for the lifecycle of my own ManagedConnections as I wish to optimise database access by reusing PreparedStatements.

      Would using standard JDBC rather than accessing connections via the Application Server's connection factory resolve this problem ?

      Is it good or bad practice to access a connection factory from within another Connector ?

      Thanks,
      Ivan

        • 1. Re: Using JDBC from within a Resource Adapter - some questio
          imcshane

          Hi,

          Just to follow up on this. Standard jdbc calls solved the problem as expected.

          I don't like the loss of connection pooling optimisations though. I'm planning on trying hibernate anyway - http://sourceforge.net/projects/hibernate - so this just makes it a bit more urgent.

          I'd still appreciate an answer to my last question. Is it normal and good practice to use one connector from another ? In my case JDBC from my own connector.

          Ivan

          • 2. Re: Using JDBC from within a Resource Adapter - some questio

            You close() the db connection to return it to the pool,
            not to destroy the connection.

            Regards,
            Adrian

            • 3. Re: Using JDBC from within a Resource Adapter - some questio
              darranl

              I think that there is also a fault in JBoss 3.0.7 regarding opening more than one connection.

              We had a situation where a session bean obtains a connection then calls a second session bean, the second session bean the obtains another connection. We were also getting the same error regarding closing the connection.

              We upgraded to JBoss 3.2.1 and the problem went away.

              I think I have seen a bug raised for this but I can not find it at the moment, it is possible that it could have been fixed in JBoss 3.0.8

              • 4. Re: Using JDBC from within a Resource Adapter - some questio
                imcshane

                Thanks for the replies guys. I'll definitely be migrating the connector to the latest version of JBoss when I get the chance.

                Regarding the close() method. I realise that this repools a connection rather than destroying it but am still unsure why repooling a connection belonging to my connector requires the repooling of any jdbc connections it was using at the time.
                If it's deliberate design rather than a bug then there are extra concerns when using one connector from another that I wasn't aware of.

                Ivan