How to do it...

There are several ways to configure the Hikari connection pool. All of them are based on the usage of the javax.sql.DataSource interface:

  1. The most obvious and straightforward method is to set the pool properties on the DataSource object directly: 
HikariDataSource ds = new HikariDataSource();ds.setPoolName("cookpool");ds.setDriverClassName("org.postgresql.Driver");ds.setJdbcUrl("jdbc:postgresql://localhost/cookbook");ds.setUsername( "cook");//ds.setPassword("123Secret");ds.setMaximumPoolSize(10);ds.setMinimumIdle(2);ds.addDataSourceProperty("cachePrepStmts", Boolean.TRUE);ds.addDataSourceProperty("prepStmtCacheSize", 256);ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);ds.addDataSourceProperty("useServerPrepStmts" ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.