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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.