Connection Pooling

Getting a JDBC connection is quite a slow operation for most databases. It can take longer than the query itself. It is not efficient to get a new connection for each JDBC statement. However, using a connection for many statements requires very careful resource management.

The standard technique to solve this challenge is to use a connection pool, where connections are held in a store for later reuse. A number of such pool implementations exist. To use one, we have to do nothing at all!

Spring Boot will automatically use HikariCP as its connection pool when it is on the classpath. Since spring-boot-starter-jdbc depends on HikariCP, it is already found and configured with sensible defaults.

If HikariCP is not on the classpath for some reason, the first fallback will be the Tomcat pooling Datasource, which you will also have available on a web project. It is actually hard not to get connection pooling with Spring Boot.