简体   繁体   English

具有HSQL的Hikari连接池在内存中

[英]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) 这是错误:(忽略上述测试用例中我没有断言statemet,因为它无法在到达断言之前无法建立连接。而且init和insert只是普通的sql来初始化和插入表/行)

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? 可能是什么问题呢?

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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM