Search code examples
javadatasourcec3p0

How do I close a java.sql.DataSource


We have a system where data is partitioned by date.
So, for example, in SqlServer we have one database per month of data. Each month partition uses a Jdbc driver Datasource wrapped in a C3P0 connection pool DataSource.

After a period of time the date range of the partition becomes old enough that we want to offline it. In that case we just remove the relevant month's DataSource from the available list.
However, ideally, when offlining I would like to "close" the DataSource so the pool relinquishes all connections to the DB.

DataSource has no close method for me to call so I'm not sure how to clean this up.

Any suggestions?


Solution

  • Looks like if you use C3PO pooled DataSources, then you can release threads and connections associated with the DataSource using DataSources.destroy(DataSource).