Pergunta

Just converting an app to JAVA 7 and wondering if anyone has had issue with try with resources and c3p0 connection pool.

I guess now JAVA automatically closes db, prepared statements and statements if you use the the try with resources.

Does it 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

Foi útil?

Solução

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 api, even old 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 should just work, without any modification, even under very old versions of the jdbc-implementing libraries.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top