HikariCP Issues with DB2

2,907 views
Skip to first unread message

Vignesh D V

unread,
Mar 21, 2016, 7:35:36 AM3/21/16
to HikariCP
Hello everyone,
I'm building a Spring Boot app with Spring Data JPA, the JPA provider being Hibernate, connection pooling with Hikari. The database is DB2.

Spring Boot version = 1.3.3
Hibernate version = 4.3.11
HikariCP version = 2.4.3

I'm using Java configuration to set the data source. Without HikariCP, the datasource configuration is as follows:

@Bean//(destroyMethod = "close")
    public DataSource dataSource(Environment env) {
            DataSource ds = DataSourceBuilder
                .create()
                .url("jdbc:db2://localhost:50000/TEST:currentSchema=TESTSchema;user=root;password=xxx;")
                .driverClassName("com.ibm.db2.jcc.DB2Driver")
                .build();
    return ds;
}

I understand the preferred way of connecting would be by using the datasource class name, however I faced some issues and this way allowed me to connect to the database.

Now to setup Hikari, I configured the same bean in the following manner:
@Bean
    public DataSource dataSource(Environment env) {
        HikariConfig config = new HikariConfig();
        config.setConnectionTimeout(30000);
        config.setIdleTimeout(30000);
        config.setMaxLifetime(2000000);
        config.setMaximumPoolSize(5);
        config.setMinimumIdle(3);
        config.setPoolName("hikari-db2-pool");

        DataSource ds = DataSourceBuilder
                .create()
                .url("jdbc:db2://localhost:50000/TEST:currentSchema=TESTSchema;user=root;password=xxx;")
                .driverClassName("com.ibm.db2.jcc.DB2Driver")
                .build();
        config.setDataSource(ds);
        HikariDataSource hds = new HikariDataSource(config)
        return hds;
    }


When I execute the above code, execution halts at with the following log line and exception stack trace:

16:53:49.607 [restartedMain] INFO  com.zaxxer.hikari.HikariDataSource - hikari-db2-pool - is starting.


After 30 seconds, the exception gets thrown,

Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException:
Exception during pool initialization: hikari-db2-pool - Connection is not available, request timed out after 30003ms.

I've tried to directly connect with hikari and connections are created and I am able to query the database via the datasource definition given above. I'm not sure what I am doing wrong.
Can someone shed some light on this?

Thanks!

Brett Wooldridge

unread,
Mar 21, 2016, 9:03:08 AM3/21/16
to HikariCP
What happens if you set a connection test query?  Also, can you enable debug logging to see if it provides any more details about why the connection cannot be acquired?

-Brett

Nitin Chauhan

unread,
Mar 21, 2016, 10:01:14 AM3/21/16
to HikariCP
Please use HikariCP version 2.4.5. It should fail instantly with 'correct' exception. and as Brett asked, please set log level to debug for hikaricp
Reply all
Reply to author
Forward
0 new messages