user6123723
user6123723

Reputation: 11106

Hikari Connection pool with HSQL In memory

public DataSource createHikariDatasource(String url, String username, String password, String driver) {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setDataSourceClassName(driver);
    hikariConfig.setUsername(username);
    hikariConfig.setJdbcUrl(url);
    hikariConfig.setPassword(password);
    hikariConfig.setConnectionTestQuery("show tables");
    DataSource ds = new HikariDataSource(hikariConfig);
    return ds;
}

And here's the test case that fails

@Test
public void createHikariCPDatasource() throws Exception {
    GreetingConfig greetingConfig = new GreetingConfig();

    String driver = "org.hsqldb.jdbc.JDBCDataSource";
    String url="jdbc:hsqldb:mem:testdb";
    String user = "SA";
    String password = "";


    logger.debug("get message data source");
    DataSource dataSource = greetingConfig.createHikariDatasource(url, user, password,driver);

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute(env.getProperty("init"));
    jdbcTemplate.execute(env.getProperty("insert"));
}

Here's the error: ( Ignore that I do not have an assert statemet in the above test case as it fails to create a connection before it can get to an assert. Also the init and insert are just plain sql to initialize and insert a table/rows)

com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: null
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:524)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:118)
    at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:71)
    at org.cam.go.microservice.GreetingConfig.createHikariDatasource(GreetingConfig.java:233)
    at org.cam.go.microservice.GreetingConfigTest.createHikariCPDatasource(GreetingConfigTest.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

What could be the problem?

Upvotes: 0

Views: 2828

Answers (1)

Pankaj
Pankaj

Reputation: 312

Works for me when I do not specify datasource class name.

Something like this

private static HikariConfig hikariConfig() {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:hsqldb:mem:customer");
        config.setUsername("sa");
        config.setPassword("");
        return config;
    }

Upvotes: 1

Related Questions