【问题标题】:java.util.NoSuchElementException: Could not create a validated object, cause: ValidateObject failedjava.util.NoSuchElementException:无法创建经过验证的对象,原因:ValidateObject 失败
【发布时间】:2012-12-07 03:04:49
【问题描述】:

我想知道以下异常是什么意思。当我设置 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

【问题讨论】:

    标签: java mysql connection-pooling


    【解决方案1】:

    我认为你打错了true

    您的代码:

    testOnBorrow=ture
    

    应该是:

    testOnBorrow=true
    

    【讨论】:

      【解决方案2】:

      这就是 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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-14
        • 2020-09-20
        • 2014-10-23
        • 2019-05-27
        • 1970-01-01
        • 2022-01-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多