1

我想知道以下异常是什么意思。当我设置 testOnBorrow=ture 时,我得到了这个。如果我设置 testOnBorrow=false,我不会得到这个。

我正在使用 MySQL 5.1.66 和 commons-pool-1.5.5.jar

Caused by: java.util.NoSuchElementException: Could not create a validated object, cause: ValidateObject failed at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1203) at org.apache.commons.dbcp.PoolingDriver.connect(PoolingDriver.java:180) ... 7 more

4

2 回答 2

1

我想你打错了true

你的代码:

testOnBorrow=ture

应该:

testOnBorrow=true
于 2013-11-06T17:18:57.910 回答
0

这就是 Tomcat 文档中关于 testOnBorrow 的内容...

testOnBorrow:

(boolean) The indication of whether objects will be validated before being borrowed from the pool. 
If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. 
NOTE - for a true value to have any effect, the validationQuery or validatorClassName parameter must be set to a non-null string. 
In order to have a more efficient validation, see validationInterval. 
Default value is false

验证查询:

(String) The SQL query that will be used to validate connections from this pool before returning them to the caller. 
If specified, this query does not have to return any data, it just can't throw a SQLException. 
The default value is null. 
Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)

https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html

于 2016-12-28T16:40:32.263 回答