简体   繁体   中英

How to create DataSource with Apache DBCP 1.4?

I'm trying this:

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();

To no avail, exception is thrown:

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)

What's wrong?

Try setting your PoolableConnectionFactory like this

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

And check if it works that way. Then check if the extra parameter related to transaction is valid in the DBCP version or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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