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: DBCP usage question
Date Fri, 25 Feb 2005 17:25:29 GMT
The BasicDataSource already does connection pooling so you can simply do:
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName(props.getProperty(dataSource + ".driver"));
bds.setUrl(props.getProperty(dataSource + ".url"));
bds.setUsername(props.getProperty(dataSource + ".user"));
bds.setPassword(props.getProperty(dataSource + ".password"));
return bds;

Also take a look at BasicDataSourceFactory.createDataSource(properties)

It doesn't handle the prefix but otherwise it creates and sets all 
known properties on a BasicDataSource.

Regards
Dirk


Vinicius Caldeira Carvalho wrote:
> Hi there I've a method to create a poolabe datasource. I read the 
> configuration from a properties file. This file has this layout
> 
> DATASOURCE_NAME.driver
> DATASOURCE_NAME.url
> 
> so I can have more than one ds per file. My method looks like this:
> 
> private DataSource setupDataSource(String dataSource) throws Exception {
> InputStream in = loader.getResourceAsStream("dbcp.properties");
> Properties props = new Properties();
> props.load(in);
> 
> GenericObjectPool connectionPool = new GenericObjectPool(null);
> connectionPool.setMaxActive(Integer.decode(props.getProperty("maxActive")).intValue());

> 
> connectionPool.setMaxIdle(Integer.decode(props.getProperty("maxIdle")).intValue()); 
> 
> 
> BasicDataSource bds = new BasicDataSource();
> bds.setDriverClassName(props.getProperty(dataSource + ".driver"));
> bds.setUrl(props.getProperty(dataSource + ".url"));
> bds.setUsername(props.getProperty(dataSource + ".user"));
> bds.setPassword(props.getProperty(dataSource + ".password"));
> 
> ConnectionFactory connectionFactory = new DataSourceConnectionFactory(bds);
> 
> PoolableConnectionFactory poolableConnectionFactory = new
> PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true); 
> 
> 
> PoolingDataSource pds = new PoolingDataSource(connectionPool);
> 
> return pds;
> 
> }
> I just 'd like to know if this is ok, or am I missing something?
> 
> thanks all


---------------------------------------------------------------------
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