June 2018
Beginner
722 pages
18h 47m
English
Keeping a database connection alive requires a significant amount of resources memory and CPU—so it is a good idea to close the connection and release the allocated resources as soon as you do not need them anymore. In the case of the pooling, the Connection object, when closed, is returned to the pool and consumes fewer resources.
Before Java 7, the way to close a connection was by invoking the close() method in a finally-block with or without a catch-block:
Connection conn = getConnection();try { //use object conn here } finally { if(conn != null){ conn.close(); }}
The code inside the finally-block is always executed, whether the exception inside the try-block was thrown or not. But since Java 7, the try...with...resources ...
Read now
Unlock full access