Connection Pooling implementation

Hi,
I realize that most J2EE containers support pooling as per the JDBC 3.0 API. But I am looking for a generic connection pooling implementation for JDBC that I can use in my applicaiton without having to write the pooling mechanism myself..
Is there a JDBC connection pool implementation out there (free would be good !), that can be integrated with any app (not neccessarily running inside a J2EE container.
Thanks

You can get one from Jakarta Commons.

Similar Messages

  • Connection pooling implementation in struts

    hi I want to implement login process in struts but now i m facing problem , I have written the code for connection pooling but now m in confusion where to call this code bcoz it should be called at once if not called earlier, so that i can use this connection object in search, add, delete, and update actions.
    thanks in advance
    pranav

    thanks a lot, but i didn't get my answer. i want to know where adjectly i need to call this connection pooling class in modal or in controller of struts?

  • Where is the connection pooling implemented?

    Hi!
    I�m a bit curious. Does anybody know where the connection pooling is implemented? Is it in the provider or in the Oracle client?
    Best regards,
    Mattias Alm�n, Consignit AB

    It is implemented in the provider.
    Thanks
    Martha

  • ResultSet problem with a jdbc connection pool implementation

    Hi
    I'm trying to use jdbc connection pool in my java application (js2e 1.4.0_01)
    from the example at http://www.developer.com/tech/article.php/626141
    In my main() code, in addition to JDBCConnection, JDBCConnectionImpl and JDBCPool classes, i use
    JDBCConnection conn;
    conn = new JDBCConnection(dbName);
    // make a statement
    sqlString = "SELECT........."
    ResultSet rs = null;
    rs = conn.sendRequest(sqlString, rs);
    // print result
    while (rs.next()) {
    Unfortunately i get an error like "ResultSet is closed" in the line corresponding to rs.next. The error disappears if i remove the line
    stmt.close();
    in the method sendRequest of the JDBCConnectionImpl class.
    1) Does anybody knows the solution?
    2) How to close all connections?
    Thanks you in advance.

    Hi ,
    You are closing the statement and then trying to use resultset , which is not going to work .So close then statment after using resultset .Ideally the code should be like this
    try {
    conn = // get the connection
    pstmt = conn.prepareStatement(sql);
    rs = pstmt.executeQuery();
    while ( rs.next()){
    // do something
    catch (Exception ex) {
    finally {
    try {
    if (rs != null)
    rs.close();
    if (pstmt != null)
    pstmt.close();
    if(conn!=null )
    conn.close();

  • How to use JDBC Connection Pools in a standalone application?

    Hi, there,
    I have a question about how to use JDBC Connection Pools in an application. I know well about connection pool itself, but I am not quite sure how to keep the pool management object alive all the time to avoid being destroyed by garbage collection.
    for example, at the website: http://www.developer.com/java/other/article.php/626291, there is a simple connection pool implementation. there are three classes:JDBCConnection, the application's gateway to the database; JDBCConnectionImpl, the real class/object to provide connection; and JDBCPool, the management class to manage connection pool composed by JDBCConnectionImpl. JDBCPool is designed by Singleton pattern to make sure only one instance. supposing there is only one client to use connection for many times, I guess it's ok because this client first needs instantiate JDBCPool and JDBCConnectionImpl and then will hold the reference to JDBCPool all the time. but how about many clients want to use this JDBCPool? supposing client1 finishes using JDBCPool and quits, then JDBCPool will be destroyed by garbage collection since there is no reference to it, also all the connections of JDBCConnectionImpl in this pool will be destroyed too. that means the next client needs recreate pool and connections! so my question is that if there is a way to keep pool management instance alive all the time to provide connection to any client at any time. I guess maybe I can set the pool management class as daemon thread to solve this problem, but I am not quite sure. besides, there is some other problems about daemon thread, for example, how to make sure there is only one daemon instance? how to quit it gracefully? because once the whole application quits, the daemon thread also quits by force. in that case, all the connections in the pool won't get chance to close.
    I know there is another solution by JNDI if we develop servlet application. Tomcat provides an easy way to setup JNDI database pooling source that is available to JSP and Servlet. but how about a standalone application? I mean there is no JNDI service provider. it seems a good solution to combine Commons DBCP with JNID or Apache's Naming (http://jakarta.apache.org/commons/dbcp/index.html). but still, I don't know how to keep pool management instance alive all the time. once we create a JNDI enviroment or naming, if it will save in the memory automatically all the time? or we must implement it as a daemon thread?
    any hint will be great apprieciated!
    Sam

    To my knoledge the pool management instance stays alive as long as the pool is alive. What you have to figure out is how to keep a reference to it if you need to later access it.

  • What's the difference between using a connection pool and a datasource

    Howdy. I figure this is a newbie question, but I can't seem to find an
    answer.
    In the docs at bea, the datasource docs say
    "DataSource objects provide a way for JDBC clients to obtain a DBMS
    connection. A DataSource is an interface between the client program and the
    connection pool. Each data source requires a separate DataSource object,
    which may be implemented as a DataSource class that supports either
    connection pooling or distributed transactions."
    In there it says the datasource uses the connection pool, but other than
    that, what is the difference between a connection pool and a datasource?

    Thanks for the info. I think it makes some sense. But it's a bit greek.
    I'm sure it'll make more sense the more I work with it. Thanks.
    "Chuck Nelson" <[email protected]> wrote in message
    news:3dcac1f5$[email protected]..
    >
    Peter,
    Here is a more formal definition of a DataSource from the Sun site
    "A factory for connections to the physical data source that thisDataSource object
    represents. An alternative to the DriverManager facility, a DataSourceobject
    is the preferred means of getting a connection. An object that implementsthe
    DataSource interface will typically be registered with a naming servicebased
    on the JavaTM Naming and Directory (JNDI) API.
    The DataSource interface is implemented by a driver vendor. There arethree types
    of implementations:
    Basic implementation -- produces a standard Connection object
    Connection pooling implementation -- produces a Connection object thatwill automatically
    participate in connection pooling. This implementation works with amiddle-tier
    connection pooling manager.
    Distributed transaction implementation -- produces a Connection objectthat may
    be used for distributed transactions and almost always participates inconnection
    pooling. This implementation works with a middle-tier transaction managerand
    almost always with a connection pooling manager.
    Does that help clarify the distinction?
    Chuck Nelson
    DRE
    BEA Technical Support

  • Connection pool for big web application

    hi,
    i am developing an application which had more then 20 classes and each class use databases.
    i made an connection bean and use it for database connectivity but as my code expand and my application run for longer time i start getting error of connection limit.
    then i start using connection pool. in this i start using one connection for whole application.
    now i want that my
    1-whole application use that connection pool and i dont need to initialize it in different classes.
    2- The main problem is that may at a time i have to connect database with different user and these connections should remain active.
    my application will be used for enterprise level and remain active for months .
    following is my connection pool
    public class ConnectionPool implements Runnable
          private Log log=new Log();
          private String driver, url, username, password;
          private int maxConnections;
          private boolean waitIfBusy;
          private Vector availableConnections, busyConnections;
          private boolean connectionPending = false;
          public ConnectionPool(String driver, String url,String username, String password,int initialConnections, int maxConnections, boolean waitIfBusy) 
              this.driver         =     driver;
              this.url            =     url;
              this.username       =     username;
              this.password       =     password;
              this.maxConnections =     maxConnections;
              this.waitIfBusy     =     waitIfBusy;
              if (initialConnections > maxConnections)
                initialConnections = maxConnections;
              availableConnections = new Vector(initialConnections);
              busyConnections = new Vector();
              try
                  for(int i=0; i<initialConnections; i++)
                    availableConnections.addElement(makeNewConnection());
              catch(Exception e)
                log.write(e.getMessage());
          }//EO constructor
      public synchronized Connection getConnection()
             if (!availableConnections.isEmpty())
                  log.write("Total connections="+availableConnections.size());
                  Connection existingConnection =  (Connection)availableConnections.lastElement();
                  int lastIndex = availableConnections.size() - 1;
                  availableConnections.removeElementAt(lastIndex);
                  // If connection on available list is closed (e.g.,it timed out), then remove it from available list
                  // and repeat the process of obtaining a connection. Also wake up threads that were waiting for a connection because maxConnection limit was reached.
                        try
                            if (existingConnection.isClosed())
                              notifyAll(); // Freed up a spot for anybody waiting
                              return(getConnection());
                            else
                              log.write(  "in available connection"  );
                              busyConnections.addElement(existingConnection);
                              return(existingConnection);
                        catch(SQLException se)
                            log.write(se.getMessage());
              } else {
                        // Three possible cases:
                        // 1) You haven't reached maxConnections limit. So establish one in the background if there isn't
                        //    already one pending, then wait for the next available connection (whether or not it was the newly established one).
                        // 2) You reached maxConnections limit and waitIfBusy flag is false. Throw SQLException in such a case.
                        // 3) You reached maxConnections limit and waitIfBusy flag is true. Then do the same thing as in second
                        //    part of step 1: wait for next available connection.
                        if ((totalConnections() < maxConnections) &&  !connectionPending)
                          makeBackgroundConnection();
                        else if (!waitIfBusy)
                            log.write("Connection limit reached");
                        // Wait for either a new connection to be established (if you called makeBackgroundConnection) or for
                        // an existing connection to be freed up.
                        try {
                          wait();
                        catch(InterruptedException ie)
                          log.write(ie.getMessage());
                  // Someone freed up a connection, so try again.
                return(getConnection());
              }//EO main if-else
          return null;
    }//EO getconnection method
      // You can't just make a new connection in the foreground
      // when none are available, since this can take several
      // seconds with a slow network connection. Instead,
      // start a thread that establishes a new connection,
      // then wait. You get woken up either when the new connection
      // is established or if someone finishes with an existing
      // connection.
      private void makeBackgroundConnection() {
        connectionPending = true;
        try {
          Thread connectThread = new Thread(this);
          connectThread.start();
        } catch(OutOfMemoryError oome) {
          // Give up on new connection
          log.write(oome.getMessage());
      public void run() {
        try {
          Connection connection = makeNewConnection();
          synchronized(this) {
            availableConnections.addElement(connection);
            connectionPending = false;
            notifyAll();
        } catch(Exception e) { // SQLException or OutOfMemory
          // Give up on new connection and wait for existing one free up.
          log.write(e.getMessage());
      // This explicitly makes a new connection. Called in
      // the foreground when initializing the ConnectionPool,
      // and called in the background when running.
      private Connection makeNewConnection()
        //log.write("make new connection with  "+url+" "+username+" "+password +" and driver= "+driver);
        Connection connection=null;
          try
            // Load database driver if not already loaded
            //Class.forName(driver);
             DriverManager.registerDriver(new OracleDriver());
            // Establish network connection to database
            connection =  DriverManager.getConnection(url, username, password);
                    if( connection.isClosed() )
                      log.write("ooooooops no connection");
                    else
                      log.write("yahoooo get connection");
          catch(Exception e)
            log.write(e.getMessage());
        return(connection);
      public synchronized void free(Connection connection) {
        busyConnections.removeElement(connection);
        availableConnections.addElement(connection);
        // Wake up threads that are waiting for a connection
        notifyAll();
      public synchronized int totalConnections() {
        return(availableConnections.size() + busyConnections.size());
      /** Close all the connections. Use with caution:
       *  be sure no connections are in use before
       *  calling. Note that you are not <I>required</I> to
       *  call this when done with a ConnectionPool, since
       *  connections are guaranteed to be closed when
       *  garbage collected. But this method gives more control
       *  regarding when the connections are closed.
      public synchronized void closeAllConnections() {
        closeConnections(availableConnections);
        availableConnections = new Vector();
        closeConnections(busyConnections);
        busyConnections = new Vector();
      private void closeConnections(Vector connections) {
        try {
          for(int i=0; i<connections.size(); i++) {
            Connection connection =
              (Connection)connections.elementAt(i);
            if (!connection.isClosed()) {
              connection.close();
        } catch(SQLException sqle) {
          // Ignore errors; garbage collect anyhow
          log.write(sqle.getMessage());
      }i get this code from internet, in which it also mention that use following code
    public class BookPool extends ConnectionPool {
    private static BookPool pool = null;
    private BookPool(...) {
    super(...); // Call parent constructor
    public static synchronized BookPool getInstance() {
    if (pool == null) {
    pool = new BookPool(...);
    return(pool);
    }if some one want to use it for whole application then use connection pool by BookPool,
    now main point is i m not getting the BookPool class could some one explain it to me???
    and second by using it can i connect to different users of DB at a time, if cant then how i can.
    its good if some one explain it by little code.
    thxxxxxxxxxxxxxxxxxx

    If this is a real, serious application and not just for practice, then why are you trying to write your own connection pool implementation?
    You'd better use Jakarta's Commons Pool and Commons DBCP, which are widely used, well tested implementations of connection pools.
    If this is a web application running in a J2EE container, you'd normally configure the connection pool in the container. The container will register the pool in JNDI and you'd look it up in JNDI from your application.
    Here's some documentation on how to do that in Tomcat 5.5: JNDI Datasource HOW-TO

  • Doubt in connection pooling

    Hi,
    I have a doubt in connection pooling.
    I we create 100 connections in a connection pool, when do the connections created or assigned? Is it during the login time or during there is a request for the connection?
    Please explain the doubt in detail.
    Thanks

    It depends on connection pool implementation.
    Anyway you should not worry about it.
    In general some connections created right away and some created after if required. You should be able to configure your pool.

  • How to dump connection pooling stats?

    OK, since the forum search is not working, can someone post the link or code to dump the connection pooling stats?
    Thanks
    Sam

    Hi,
    Assuming that you are using BC4J and assuming that you are using BC4J's connection pool implementation (default if you have specified a JDBC URL connection type in your configuration) then you can dump connection pool statistics by executing something like the following (9.0.2) on the server tier after the first AM connection has been established:
    import oracle.jbo.server.*;
    import oracle.jbo.pool.*;
    import java.util.Enumeration;
          ResourcePoolManager mgr = (ResourcePoolManager)ConnectionPoolManagerFactory.getConnectionPoolManager();
          Enumeration keys = mgr.getResourcePoolKeys();
          while (keys.hasMoreElements())
             Object key = keys.nextElement();
             System.out.println("Dumping statistics for connection pool:  " + key);
             ResourcePool cPool = (ResourcePool)mgr.getResourcePool(key);
             cPool.dumpPoolStatistics(new java.io.PrintWriter(System.out, true));
    If you are not using BC4J or are using a JDBC DataSource then you will have to consult the documentation for that DataSource.
    Hope this helps.
    JR

  • Can anyone tell me about Connection Pools???

    Hi,
    Is there a freely downloadable Connection Pool implementation available on the net? I need it specifically for Oracle databases... This is for a prod environment and am looking for a stable implementation... Any good information/links is most appreciated.
    Thanks
    Prowzen

    Hi,
    I actually implemented it long time back. This is a best case to implement the Singleton Pattern. Just to give an idea, here is how it goes. I'll try to post the code too but cannot guarantee it right now.
    Basically the Pool information like the database, userid, password, SID etc. should be configurable through a properties file as you are saying that it is a production environment.
    1. Implement your Connection Pool as a Singleton class that has methods like init, getConnection, releaseConnection, createConnection etc. Have private member - a java.util.Vector of java.sql.Connection objects.
    2. Anyone who wants to use the connection pool gets an instance with the getInstance method which will call init method.
    3. The init should read the properties file and get the necessary details. Then create required number of connections and put them in the Vector of connections (pool). You are good to go now. Ideally this should all be done at the startup of the whole Application.
    4. Each client will call the getConnection method of the Singleton. The getConnection should Synchronize the Vector and remove the connection at index 0 of the pool (vector) and return it.
    i.e. public java.sql.Connection getConnection ()
    //wait until someone notifies me after returning a connection back to the pool
    if(connectionPool_.size() == 0)
    wait();
    Connection con = null;
    synchronized(connectionPool_)
    con = (Connection)connectionPool_.elementAt(0);
    connectionPool_.removeElementAt(0);
    return con;
    5. Each client SHOULD call the releaseConnection method of the Singleton once it is done using the connection. The releaseConnection should Synchronize the Vector and add the connection back to the pool.
    So, basically the connections in the pool will be used in a Round-Robin Fashion.
    i.e. public void releaseConnection (java.util.Connection con)
    connectionPool_.addElement(con);
    //Notify all the waiting Clients. Let JVM decide who gets the connection.
    notifyAll();
    return con;
    This is the core logic of what I had written. But there are lot of other cases that you need to consider to write robust code like Lost Connections, when you need to throw that connection away from the pool and add a new one. This is more so significant in busy databases configured to timeout inactive connections. I used to have a low priority thread kicked off at the start along with this main pool that would wake up around 4 or 5 in the night and replenish all the connections in the pool so that it will be good to go for one more day before it gets replenished again. Of course, in such a case, the clients have to have a retry mechanism in case you don't respond in reasonable amount of time while replenishing the connection pool.
    Hope this helps.
    Amar.

  • Application Server and Driver  Connection Pool

    Hi,
    What is the difference between Connection Pool implemented by the Driver and the Connection Pool implemented by the Application Server?
    If i am using a JDBC3.0 compliant driver,i can use PooledDataSource to get a Conenction from the Connection pool. But, even otherwise, the application server (JBOSS) would implement a Connection Pooling mechanism. i.e even from a basic Datasource, i will get the Connection Pool.
    1. Can i do away with PooledDataSource of Driver when using an application server?
    2. If i have to use both, then what is the criterion for optimal usage?
    Can someone answer this please...
    If there is some reference available on this topic, please let me know.
    Thanks in Advance

    Connection pooling is good that the connection object that have been created can be used later by other client.
    Application server is better since server always have more resources( such as memory, processor speed) in order to perform the task.
    And this may improve centralization, all connection object managed by a single centralized server.
    Pls correct me if i am wrong.

  • Universal Connection Pool license and release policy

    Hi,
    the Oracle JDBC drivers are licensed by the "Oracle Technology Network Development and Distribution License Terms" which allows you to distribute the JDBC drivers with your software without the need to purchase any additional license from Oracle.
    UCP is licensed by the "Oracle Technology Network Developer License Terms". This license is the same you get for your development version of the database itself, meaning that you are not allowed to use the software for any production use or development of an already released software.
    This is irritating, since I cannot see that I can purchase a license for UCP to distribute UCP with my software. In addition, the version of UCP currently available at oracle.com is not the most current one (11.2.0.1.0; Oracle database patchset 11.2.0.2.0 contains UCP version 11.2.0.2.0).
    Another issue is that the connection pool implementation bundled with the Oracle JDBC driver is deprecated, so UCP is the only option to go with in the long run.
    Could someone help me to clarify the licence and release strategy for UCP?
    Thanks,
    Ulf

    You can either require a customer to download it themselves or perhaps even automate the download as part of your install.
    Other than that I can only mention that my expectation is that you will not get an answer from Oracle (a rep) unless you have a monetary relationship with them. If you have a good customer that has purchased an Oracle license they might be able to ask for you via their support license.

  • ActiveMQ Connection Pool

    Does anybody knows how to maintain connection pool implementation in ActiveMQ and JbossMQ based on JMS ?
    thanks

    If you are using Spring's JmsTemplate to send messages then there is a PooledConnectionFactory you can use...
    http://activemq.org/Spring+Support
    However if you want a general purpose JMS pool and want to support both inbound and outbound messaging and want to handle either JMS transactions or XA then I'd heavily recommend Jencks
    http://jencks.org/
    e.g.
    http://jencks.org/Message+Driven+POJOs
    http://jencks.org/Outbound+JMS
    James
    http://logicblaze.com/

  • Connection pool running out of connections

    Hi all,
    I am using Oracle's connection pool implementation:
    OracleConnectionPoolDataSource dbConnection;
    OracleConnectionCacheImpl connectionPool;
    and tomcat 3 and 4. Sometimes on Tomcat 4 (Linux) I see that the connections are not being reutilized and therefore I run out of free connections. The same application runs fine on NT and Tomcat 3 and 4. I checked all my methods and all have a close(connection) in my finally{} and besides this the problem only happens once in a while and the program is using the same methods all the time. Anybody has a clue about what could the issue be?
    Thanks,
    A.

    have u tried setCacheScheme?

  • Connection Pooling in EJBContainer if Driver already implements

    Hi,
    Can anybody explain the mechanism in an EJBContainer if the Driver for a particular database already implements the Connection pooling ie JDBC2.0X feature. Does the EJBContainer utilize the already pooled connections or the Container uses it own implementation of the pooledConnection interface.
    Thanks in advance
    neo

    the Container uses it own implementation of the pooledConnection interface.
    you have to make connection pool in the property file
    in weblogic we make connection pool in the weblogic.property file
    which server u r using

Maybe you are looking for