Connection Pooling leads to unlimited Connetions in SQL server

Discussions

EJB design: Connection Pooling leads to unlimited Connetions in SQL server

  1. Connection pooling in Sun Application Server leads to create unlimited connections in my sql server,help.
    How to count no. of object in each pool?
    how to delete objects from a connection pool ?
  2. Are u sure you are correctly disposing your connections.

    You have to follow this principle:

    void myMethod(DataSource ds) throws SQLException
    {
      Connection conn = ds.getConnection();
      try
      {
        // do something...
      }
      finally
      {
        conn.close();
      }
    }

    Notice that ONLY when connection is successfully retrieved from the DataSource your code enters into TRY/FINALLY block and no matter what happens in your code, FINALLY block is always called and connection is closed (e.g. returned to the connection pool...

    To aid your code review, I reccomend "HAMMURAPI" Java code review tool. It has code instectors that check if you are correctly handle connections and other resources.
    Here is the link: http://www.hammurapi.org
  3. If you are using EJB's and transactions, resource such as Connections/Statements won't be released until the transaction is either committed or rolled back. If you don't need transactions on your EJB's use never or not supported. And, as always, make sure you close your Connection/ResultSet/Statement Objects in a finally clause.

    Hope this helps -
    Jon
  4. Oh, you can use the asadmin utility and monitoring to determine the number of open connections in the connection pool.