Java SpringJDBCTemplate是apache commons以外的其他MySQL数据源吗?

Java SpringJDBCTemplate是apache commons以外的其他MySQL数据源吗?,java,spring,datasource,jdbctemplate,Java,Spring,Datasource,Jdbctemplate,我使用Spring JDBCTemplate在apache commons数据源(org.apache.commons.dbcp.BasicDataSource)上执行SQL操作,当服务启动并运行很长时间后,我最终得到以下异常: org.springframework.dao.RecoverableDataAccessException: StatementCallback; SQL [SELECT * FROM vendor ORDER BY name]; The last packet su

我使用Spring JDBCTemplate在apache commons数据源(org.apache.commons.dbcp.BasicDataSource)上执行SQL操作,当服务启动并运行很长时间后,我最终得到以下异常:

org.springframework.dao.RecoverableDataAccessException: StatementCallback; SQL [SELECT * FROM vendor ORDER BY name]; The last packet successfully received from the server was 64,206,061 milliseconds ago.  The last packet sent successfully to the server was 64,206,062 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 64,206,061 milliseconds ago.  The last packet sent successfully to the server was 64,206,062 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:406)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:463)
    at com.cable.comcast.neto.nse.taac.dao.VendorDao.getAllVendor(VendorDao.java:25)
    at com.cable.comcast.neto.nse.taac.controller.RemoteVendorAccessController.requestAccess(RemoteVendorAccessController.java:78)
我已尝试将“autoReconnect=true”添加到连接字符串中,但此问题仍然存在。是否可以使用其他数据源为我管理重新连接

您可以尝试使用C3PO:


格雷廷斯
pacovr

BasicDataSource可以为您管理保持连接的活动状态。您需要设置以下属性:

minEvictableIdleTimeMillis = 120000 // Two minutes
testOnBorrow = true
timeBetweenEvictionRunsMillis = 120000 // Two minutes
minIdle = (some acceptable number of idle connections for your server)
这些将配置数据源以持续测试您的连接,并在连接过期时将其删除。在基本数据源上有许多其他属性,您可能需要考虑检查,以便调整连接池性能。我在过去遇到过一些奇怪的问题,我的数据库访问有问题,这一切都归结于连接池是如何配置的

minEvictableIdleTimeMillis = 120000 // Two minutes
testOnBorrow = true
timeBetweenEvictionRunsMillis = 120000 // Two minutes
minIdle = (some acceptable number of idle connections for your server)