[opencms-dev] How to use the connection pool?

Thomas.Zirnsack at gfk.de Thomas.Zirnsack at gfk.de
Wed Aug 1 16:25:17 CEST 2001

Hi Andreas,

thanks for your quick reply. I will test this solution.

Maybe it would be of interest to you (and others), that I have found
another solution meanwhile. I am using the Protomatter pool.

Find an example below. I just had to make changes to the
DmsDatabase.class (now accepts a connection pool string in
one constructor, the construcutor with no argument still sets the pool
the opencms pool).

Kind regards,

//  code starts
import java.util.*;
import java.sql.*;
import com.protomatter.jdbc.pool.*;

class Test

   public static void main(String[] argus)
   throws ClassNotFoundException, Exception


      // initialization params are kept in a Hashtable
      Hashtable args = new Hashtable();

      // the underlying driver
      args.put("jdbc.driver", "com.sybase.jdbc2.jdbc.SybDriver");

      // the URL to connect the underlyng driver with the server
      args.put("jdbc.URL", "jdbc:sybase:Tds:x.x.x.xx:y/opencms");

      // these are properties that get passed
      // to DriverManager.getConnection(...)
      Properties jdbcProperties = new Properties();
      jdbcProperties.put("user", "user");
      jdbcProperties.put("password", "password");
      args.put("jdbc.properties", jdbcProperties);

      // the initial size of the pool.
      args.put("pool.initialSize", new Integer(5));

      // the maximum size the pool can grow to.
      args.put("pool.maxSize", new Integer(10));

      // each time the pool grows, it grows by this many connections
      args.put("pool.growBlock", new Integer(2));

      // between successive connections, wait this many milliseconds.
      args.put("pool.createWaitTime", new Integer(2000));

      // finally create the pool and we're ready to go!
      JdbcConnectionPool myPool
        = new JdbcConnectionPool("myPool", args);

      String url = "jdbc:protomatter:pool:myPool";

      // this is my code (starts)
      // if I call w/o the url it will use the OpenCMS connection pool
      // by default.
      DmsDatabase ddb = new DmsDatabase(url);

      DmsTreeEntryDoc dtec = ddb.getDmsTreeEntryDoc(2007);
      System.out.println("->" + dtec.getDisplay() + "|" + dtec.getSystem
      // this is my code (ends)


// code ends.

                    Andreas Schouten                                                                                         
                    <Andreas.Schouten at framf        An:     "'opencms-dev at www.opencms.com'" <opencms-dev at www.opencms.com>     
                    ab.de>                         Kopie:                                                                    
                    Gesendet von:                  Blindkopie:                                                               
                    owner-opencms-dev at www.o        Thema:  Re: [opencms-dev] How to use the connection pool?                 
                    01.08.01 15:10                                                                                           
                    Bitte antworten an                                                                                       



you cannot register a pool like this:

// code starts
CmsPool cp = new CmsPool

(After this you have created a pool, but the CmsDriver don't know that it

OpenCms manages the pools itself. Therefor it creates a pool on demand it
asked the first time with:

con = DriverManager.getConnection("jdbc:opencmspool:genericsql");

So you have to configurate the pool in a property file (like you have seen
in the opencms.properties). Use code like this:

        // set configurations for the dbpool driver

"config" is the configuration-object that reads from the properties-file.

After that you can use:

con = DriverManager.getConnection("jdbc:opencmspool:genericsql");



More information about the opencms-dev mailing list