commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vinicius Caldeira Carvalho <vinicius.carva...@squadra.com.br>
Subject DBCP usage question
Date Tue, 22 Feb 2005 13:14:51 GMT
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