commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <dirk.verbe...@pandora.be>
Subject Re: AW: [DBCP] How to set connectionProperties?
Date Tue, 21 Jun 2005 05:58:19 GMT
When using the manual pooling driver model you have to put/set the 
properties in different places.
Username & password go into the DriverManagerConnectionFactory.
ValidationQuery has to be set on PoolableConnectionFactory
The other properties can be set on the GenericObjectPool.

For each property you will find a setter, except for initialSize, you 
have to do something like:
             for (int i = 0 ; i < initialSize ; i++) {
                 connectionPool.addObject();
             }

A bit more work but its just a matter of finding all the setters.

Cheers
Dirk



Frank Fischer wrote:
> Hi Dirk
> 
> Thanks a lot for your answer.
> 
> In fact, i'm constructing the connection pool myself based on the manual
> pooling driver model example. That's working fine so far - db connections
> are created and i can pass SQL statements to the db.
> 
> Here's what i do:
> 
> -------------------
> 
>         DBURL =  "jdbc:mysql://" + SQLServer + "/" + SQLDatabase;
>                 
>         Properties DBCPProps = new Properties();
>         DBCPProps.setProperty("user", SQLUser);
>         DBCPProps.setProperty("password", SQLPassword);
>         DBCPProps.setProperty("initialSize", "4");
>         DBCPProps.setProperty("maxActive", "32");
>         DBCPProps.setProperty("maxIdle", "8");
>         DBCPProps.setProperty("minIdle", "4");
>         DBCPProps.setProperty("maxWait", "8000");
>         DBCPProps.setProperty("validationQuery", "SELECT 1");
>         DBCPProps.setProperty("testOnBorrow", "true");
>         DBCPProps.setProperty("testOnReturn", "true");
>         DBCPProps.setProperty("testWhileIdle", "true");
>         DBCPProps.setProperty("timeBetweenEvictionRunsMillis", "3000");
>         DBCPProps.setProperty("numTestsPerEvictionRun", "3");
>         DBCPProps.setProperty("minEvictableIdleTimeMillis", "1");
> 
> 
>         // load the underlying JDBC driver.
>         try 
>         {
>             Class.forName(OriginalDriverName);
>              // set up and register the PoolingDriver.
>    
>             // First, we'll need a ObjectPool that serves as the actual pool
> of connections.
>             // We'll use a GenericObjectPool instance, although  any
> ObjectPool implementation will suffice.
>             ObjectPool connectionPool = new GenericObjectPool(null);
>             
>             // Next, we'll create a ConnectionFactory that the pool will use
> to create Connections.
>             // We'll use the DriverManagerConnectionFactory
>             ConnectionFactory connectionFactory = new
> DriverManagerConnectionFactory(connectURI, props);
>             
>             // Now we'll create the PoolableConnectionFactory, which wraps
> the "real" Connections created by the ConnectionFactory with
>             // the classes that implement the pooling functionality.
>             PoolableConnectionFactory poolableConnectionFactory = new
> PoolableConnectionFactory(connectionFactory, connectionPool, null, null,
> false, true);
> 
>             // Finally, we create the PoolingDriver itself...
>             Class.forName("org.apache.commons.dbcp.PoolingDriver");
>             PoolingDriver driver = (PoolingDriver)
> DriverManager.getDriver("jdbc:apache:commons:dbcp:");
> 
>             // ...and register our pool with it.
>             driver.registerPool(PoolName, connectionPool);
>         } 
>         
>         catch (Exception e) 
>         {
>         }
> -------------------
> 
> This fragment works so far, meaning, the connection to db can be established
> (meaning also username and password are read from props) but none of the
> remaining properties seem to have an effect. I.e. the pool always starts
> with initialSize=0.
> 
> How do i set the remaining properties? Can this be done using this way or do
> i have to create the whole pool manually using
> GenericObjectPool/DriverConnectionFactory/GenericKeyedObjectPoolFactory/Pool
> ableConnectionFactory?
> 
> Greetings, Frank
> 
> 
>>-----Urspr√ľngliche Nachricht-----
>>Von: Dirk Verbeeck [mailto:dirk.verbeeck@pandora.be] 
>>Gesendet: Samstag, 18. Juni 2005 12:46
>>An: Jakarta Commons Users List
>>Betreff: Re: [DBCP] How to set connectionProperties?
>>
>>If you use a BasicDataSource then you can use the 
>>addConnectionProperty(String name, String value) method.
>>
>>If you are constructing a DB pool yourself you should use the 
>>following
>>constructor:
>>new DriverConnectionFactory(driver, url, connectionProperties)
>>
>>-- Dirk
>>
>>Frank Fischer wrote:
>>
>>>Hi all
>>> 
>>>I'm using the ConnectionPool and it's working fine so far. 
>>
>>Only thing 
>>
>>>i do not know how to do, is to set the connectionProperties (like 
>>>minIdle and so on). Since i'm using an ApplicationServer nor 
>>>Datasources, i can not set them using a properties-File but need to 
>>>know how they can be set directly on the ConnectionPool.
>>>
>>>Does anyone know how this can be done?
>>> 
>>>Thanks a lot for your support!
>>>
>>>Kind regards
>>>Frank
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message