Varghese Renny wrote:0 down vote favorite
A webapp written according to accepted standards obtains database connections from a connection pool that is constructed, owned, and maintained by the server. This pool can actually be defined at a level that allows sharing it between multiple webapps, depending on how the server.xml file was configured.
Regardless, since the whole point of having a pool is that the pool holds open database connections so that the system will be spared the overhead of repeatedly creating and destroying them, there's not a whole lot of support for physically closing connections - the pool connections are façades for actual Connection objects, where the pool connection's close() method simply returns the underlying open Connection back to the pool.
If you undeploy a webapp, that should cause the pool to be eligible for garbage collection, which should in turn make the Connection objects collectible, which will eventually shut down the Connection. Without checking the Tomcat source, however, I don't know if there's an explict "terminate pool" API method that Tomcat can use to forcibly cause the pool to clean up on command rather than whenever the garbage collector gets around to it.
All in all, the simplest and most reliable way to release all those connections would be to terminate Tomcat itself. For most uses, that's sufficient.