gpt4 book ai didi

java - 如何使用 Apache DBCP 1.4 创建数据源?

转载 作者:行者123 更新时间:2023-12-01 15:40:39 24 4
gpt4 key购买 nike

我正在尝试这个:

final PoolableConnectionFactory factory = new PoolableConnectionFactory(
new DriverManagerConnectionFactory("jdbc:hsqldb:mem:testdb", "sa", ""),
new GenericObjectPool(null),
null,
"SELECT 1 from INFORMATION_SCHEMA.SYSTEM_USERS",
true,
false,
Connection.TRANSACTION_NONE
);
DataSource ds = new PoolingDataSource(factory.getPool());
ds.getConnection();

无济于事,抛出异常:

java.util.NoSuchElementException: Could not create a validated object, cause: Invalid argument in JDBC call
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1191)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)

出了什么问题?

最佳答案

尝试像这样设置你的 PoolableConnectionFactory

PoolableConnectionFactory factory = new PoolableConnectionFactory(
new DriverManagerConnectionFactory("jdbc:hsqldb:mem:testdb", "sa", ""),
new GenericObjectPool(null),
null, null, false, true);

并检查它是否可以这样工作。然后检查与事务相关的额外参数在DBCP版本中是否有效。

关于java - 如何使用 Apache DBCP 1.4 创建数据源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8096515/

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