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

Jeroen Habets jeroen.habets at framfab.nl
Thu Aug 2 12:41:50 CEST 2001


I have problems with the connection pool. Sometimes when I want to release
the connection the connection is already closed...
Can it be that closing the resultset of a prepared statement on the
connection also closes the connection?

Jeroen

> -----Original Message-----
> From: Thomas.Zirnsack at gfk.de [mailto:Thomas.Zirnsack at gfk.de]
> Sent: Wednesday, August 01, 2001 16:25
> To: opencms-dev at www.opencms.com
> Subject: Re: [opencms-dev] How to use the connection pool?
> 
> 
> 
> 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,
> tom
> 
> //  code starts
> import java.util.*;
> import java.sql.*;
> import com.protomatter.jdbc.pool.*;
> 
> class Test
> {
> 
>    public static void main(String[] argus)
>    throws ClassNotFoundException, Exception
>    {
> 
>       
> Class.forName("com.protomatter.jdbc.pool.JdbcConnectionPoolDriver");
> 
>       // 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?                 
>                     pencms.com                                
>                                                                
>                                                               
>                                                                
>                                                               
>                                                                
>                     01.08.01 15:10                            
>                                                                
>                     Bitte antworten an                        
>                                                                
>                     opencms-dev                               
>                                                                
>                                                               
>                                                                
>                                                               
>                                                                
> 
> 
> 
> 
> Class.forName("com.opencms.dbpool.CmsDriver");
> 
> Hi,
> 
> you cannot register a pool like this:
> 
> // code starts
> CmsPool cp = new CmsPool
>          (
>             "jdbc:opencmspool:genericsql",
>             "com.sybase.jdbc2.jdbc.SybDriver",
>             "jdbc:sybase:Tds:x.x.x.x:y/opencms",
>             "user",
>             "password",
>             10,
>             20,
>             5,
>             120,
>             360
>          );
> 
> (After this you have created a pool, but the CmsDriver don't 
> know that it
> exists)
> 
> OpenCms manages the pools itself. Therefor it creates a pool 
> on demand it
> is
> 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
>         com.opencms.dbpool.CmsDriver.setConfigurations(config);
> 
> "config" is the configuration-object that reads from the 
> properties-file.
> 
> After that you can use:
> 
> con = DriverManager.getConnection("jdbc:opencmspool:genericsql");
> 
> Regards,
> 
> Andreas
> 
> 
> 



More information about the opencms-dev mailing list