I'm converting an app to Java 7 and I'm wondering if anyone has had issue with try-with-resources and the c3p0 connection pool.
I guess now Java automatically closes db, prepared statements and statements if you use the the try-with-resources. Does this mean that the underlying APIs such as the JDBC driver and c3p0 must implement AutoClosable?
I'm using c3p0 0.9.2.1 and jTDS 1.3.0.
We get this one for free!
JDBC resources (Connection
, Statement
, ResultSet
) have always offered a close()
method. As of Java 7, those interfaces inherit AutoCloseable
. When run under Java 7, even older implementations will inherit that interface. Since they already have close() methods that do the right thing, these implementations will fulfill the contract of that interface.
So, try-with-resource will just work, without any modification, even under very old versions of a JDBC-implementing library.