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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
