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?
Best approach to close JDBC connection objectThe rs. close() closes the ResultSet object and doesn't allow to process the ResultSet object further. The st. close() closes the Statement object that is we can't send further queries to database software using that statement object.
If you don't close it, it leaks, and ties up server resources. @EJP The connection itself might be thread-safe (required by JDBC), but the applications use of the connection is probably not threadsafe.
Completely Open and Close A Database Connection If any database connection is open then it takes the resources of the database such as memory, cursors, locks , temporary tables all are are engaged. To release the connection object it is very important to close the database connection after it is used.
It is always better to close the database/resource objects after usage. Better close the connection, resultset and statement objects in the finally block. Until Java 7, all these resources need to be closed using a finally block.
Looks like if you use C3PO pooled DataSources, then you can release threads and connections associated with the DataSource using DataSources.destroy(DataSource).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With