April 2018
Intermediate to advanced
202 pages
4h 48m
English
When using a connection pool, the pool implementation takes care of closing the JDBC connections. Depending on the specific implementation, you might have to invoke this process. Usually, you want the pool to be active during the lifetime of your web application. Remember the ServletContextListener implementation we used to initialize the connection pool? Well, we can use it to shut the pool down. All we need to do is to implement the contextDestroyed method:
@WebListenerpublic static class JdbcExampleContextListener implements ServletContextListener { ... @Override public void contextDestroyed(ServletContextEvent sce) { DatabaseService.shutdown(); }}
Finally, the shutdown method is implemented as follows:
Read now
Unlock full access