in bmp how to return a connection to the pool

Discussions

EJB design: in bmp how to return a connection to the pool

  1. hai everybody,

    i am getting a connection from the pool in case of BMP as follows-

    public Connection getConnection()
    {
    DataSource ds =(javax.sql.DataSource) ic.lookup("java:comp/env/jdbc/demopool");
    return ds.getConnection();
    }

    after getting a connection from as -

    Connection c = getConnection() ;

    we are using it for database interaction and we are closing the connection as -

    c.close();

    we hope that we are returning the connection back to pool.

    we give jdbc properties as:
     
          weblogic.jdbc.connectionPool.demoPool=\
           url=jdbc:odbc:project1,\
           driver=sun.jdbc.odbc.JdbcOdbcdriver,\
           initialCapacity=1,\
           maxCapacity=4,\
           capacityIncrement=1,\
           props=user=sa;password=;server=infoserver

    ques: after the 3 times connected to the server , it getting a error as:

    Pool connect failed:None available

    why this error is coming? we are closing each connection after every transaction with database, then is the connection going to the pool or not.if not , why?

    waiting for your reply...


  2. Hi,
     Make sure u r closing ur connections in the finally block, so that, the connections r released and returned to the pool, even when an exception occurs.
     Hope this works,

    thx,
    Manohar(manoharm at planetasia dot com)
  3. Hi,
    change your maxcapacity in the properties file to 7 and try again.

    regards,
    Sagar.
  4. yes ,

    i changed the maxcapacity to some high number , once i hit the server (that many times - 1) times , then i am getting the same problem . why that should come when the connection is returned to the pool?

    with regards
    k.ramakrishna
  5. yes ,

    i changed the maxcapacity to some high number , once i hit the server (that many times - 1) times , then i am getting the same problem . why that should come when the connection is returned to the pool?

    with regards
    k.ramakrishna
  6. From the WLS console, you can verify if the connections are infact returned to the pool. If it is not, then revisit your code.



  7. Hi,
      The app server is going to manage your connections for you. Do not close the connection. Get the connection from the datasource. Once the pool limit is reached, no more new connections will be created. Now the getconnection caalls will be handed connections from this pool.
    When the connection goes out of scope, it will be returned to the pool.
    Regards
    Anuj
  8. Hi Anuj,

    The app server is going to manage your connections for you.
    * yes i agree with this.
     Do not close the connection.
    * no. u have to close the connection.
    Get the connection from the datasource. Once the pool limit is reached, no more new connections will be created.
    * yes once again

    Now the getconnection calls will be handed connections from this pool.
    When the connection goes out of scope, it will be returned to the pool.
    * NO. when the connection goes out of scope, it WILL NOT be returned to the pool. A db connection (also network socket connection, file i/o) are all resources outside the jvm. These have to be explicitly closed. Once it goes out of scope, u will not be able to access it any more because the reference for it is lost. but still connection wont be returned to the pool until u
    1. close the connection.
    2. restart the server.
    3. refresh the connections of ur pool.

    thx,
    Manohar(manoharm at planetasia dot com)
  9. Hi Manohar,
      A couple of things. I am talking with reference to iPlanet App server (other servers might do things differently). I am also using global connections (conections used within transactional context that is being managed by the container).

    Given the above, the database connection is tied to the thread that initiated the transaction.This connection will be reused by the transactions that get executed on this thread. Hence you DONOT want to close the connection.

    You are correct, though, about the connection not being closed when it goes out of scope.

    Thanks and Regards
    Anuj
    =======================================================
    The app server is going to manage your connections for you.
       * yes i agree with this.

    Do not close the connection.
       * no. u have to close the connection.

    Get the connection from the datasource. Once the pool limit is reached, no more new connections will be created.
       * yes once again

    Now the getconnection calls will be handed connections from this pool. When the connection goes out of scope, it will be returned to the pool.
       * NO. when the connection goes out of scope, it WILL NOT be returned to the pool. A db connection (also network socket connection, file i/o) are all resources outside the jvm. These have to be explicitly closed. Once it goes out of scope, u will not be able to access it any more because the reference for it is lost. but still connection wont be returned to the pool until u
        1. close the connection.
        2. restart the server.
        3. refresh the connections of ur pool.
  10. Hi,

    try defining a datasource on the demopool. eg.Add this to the property file

    weblogic.jdbc.DataSource.demoSource=demoPool

    then get the connection from the source

    javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("demoSource");


    Mujeer