gpt4 book ai didi

java - Hikari 内存中 HSQL 连接池

转载 作者:行者123 更新时间:2023-12-01 10:02:19 26 4
gpt4 key购买 nike

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

这是失败的测试用例

@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"));
}

这是错误:(忽略我在上面的测试用例中没有断言语句,因为它无法在到达断言之前创建连接。此外,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)

可能是什么问题?

最佳答案

当我不指定数据源类名时,适用于我。

类似这样的事情

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

关于java - Hikari 内存中 HSQL 连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36701485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com