how to return a connection in c3p0

耗尽温柔 提交于 2019-12-05 01:52:01

This is initializing code

private DataSource init() {

    DataSource unpooled = DataSources.unpooledDataSource(DB_URL, DB_USERNAME, DB_PASSWORD);

    Map<String, Object> overrideProps = new HashMap<String, Object>();

    overrideProps.put("maxPoolSize", MAX_POOL_SIZE);
    overrideProps.put("minPoolSize", MIN_POOL_SIZE);

    return DataSources.pooledDataSource(unpooled, overrideProps);
}

And you get connection from DataSource.

public Connection getConnection() throws SQLException {
    return dataSource.getConnection();
}

And to close the connection just call close() method.

connection.close();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!