Once the connection is closed, no further JDBC requests can be made against objects created from the connection. Do not explicitly close the Connection object until you no longer need it for executing statements.
The Connection interface extends AutoCloseable in JDK 7 and after. If you declare a connection in a try-with-resources statement and there is an error that the code does not catch, the JRE will attempt to close the connection automatically.
Note that a transaction-severity or higher exception causes
It is therefore always best to catch errors inside the try-with-resources block and to either roll back or commit, as appropriate, to ensure that there is no pending transaction when leaving the try-with-resources block. This action also improves application portability, since DBMSs differ in their semantics when trying to close a connection with a pending transaction.
The following table describes features of Connection methods that are
specific to
See