生产环境问题如下:

org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:634)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:408)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:332)
    at ins.framework.dao.EntityDaoHibernate.findByHql(EntityDaoHibernate.java:311)
    Truncated. see log file for complete stacktrace
Caused By: org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
    Truncated. see log file for complete stacktrace
Caused By: weblogic.jdbc.extensions.PoolLimitSQLException: weblogic.common.resourcepool.ResourceLimitException: No resources currently available in pool salesDataSource to allocate to applications, please increase the size of the pool and retry..
    at weblogic.jdbc.common.internal.JDBCUtil.wrapAndThrowResourceException(JDBCUtil.java:252)
    at weblogic.jdbc.pool.Driver.connect(Driver.java:142)
    at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:658)
    at weblogic.jdbc.jts.Driver.connect(Driver.java:127)
    at weblogic.jdbc.common.internal.RmiDataSource.getConnectionInternal(RmiDataSource.java:548)
    Truncated. see log file for complete stacktrace

本地测试如下: 设置数据源连接数最大为15,超过15则会报错

 ​​​​

 最终排查问题为小伙伴在使用Connection链接数据库时,只关闭了ResultSet,Connection没有关闭PreparedStatement,

Connection关闭并不是物理关闭,只是归还连接池,所以PreparedStatement和ResultSet都被持有,并且实际占用相关的数据库的游标资源,在这种情况下,只要长期运行,往往就会报“游标超出数据库允许的最大值”的错误,导致程序无法正常访问数据库,所以使用Connection连接数据库的时候一定要关闭Connection,一定要关闭ResultSet,一定要关闭PreparedStatement

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐