当前位置: 代码迷 >> J2EE >> org.hibernate.exception.GenericJDBCException: Cannot open connection
  详细解决方案

org.hibernate.exception.GenericJDBCException: Cannot open connection

热度:477   发布时间:2016-04-22 02:43:02.0
数据库连接池爆满异常(顶者送分)
当我多次刷新页面,或者在页面间来回跳转个几次,(也就是多次访问数据库了),就出现这异常,mysql数据库

exception 
javax.servlet.ServletException: org.hibernate.exception.GenericJDBCException: Cannot open connection
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)

root cause 
java.sql.SQLException: Couldn't get connection because we are at maximum connection count (10/10) and there are none available
org.logicalcobwebs.proxool.Prototyper.quickRefuse(Prototyper.java:309)
org.logicalcobwebs.proxool.ConnectionPool.getConnection(ConnectionPool.java:158)
org.logicalcobwebs.proxool.ProxoolDataSource.getConnection(ProxoolDataSource.java:97)
org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:82)

说已经超过最大连接数10个,可是很奇怪我同样代码在家都OK,在公司怎么就出现这异常,(在公司数据库是连的一台服务器192.168.1.229)
因为spring 管理的那个sessionFactory,我是直接自己写的BaseDAO,被用于其他的DAO继承,来获取连接,

以下是我的applicationContext.xml,红色部分是我的BaseDao,我没有配置事务,老大是在服务层配置的事务,我是在DAO层操作,不一定得配置事务才行啊
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="driver" value="${proxool.driver}" />
<property name="driverUrl" value="${proxool.url}" />
<property name="user" value="${proxool.username}" />
<property name="password" value="${proxool.password}" />
<property name="alias" value="${proxool.alias}" />
<property name="houseKeepingSleepTime" value="${proxool.houseKeepingSleepTime}" />
<property name="prototypeCount" value="${proxool.prototypeCount}" />
<property name="maximumConnectionCount" value="${proxool.maximumConnectionCount}" />
<property name="minimumConnectionCount" value="${proxool.minimumConnectionCount}" />
<property name="trace" value="${proxool.trace}" />
<property name="verbose" value="${proxool.verbose}" />
</bean>


<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
<!--Hibernate SessionFatory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/goodstart/core/security/model/hbm/Resource.hbm.xml</value>
<value>com/goodstart/core/security/model/hbm/Role.hbm.xml</value>
<value>com/goodstart/core/security/model/hbm/User.hbm.xml</value>
<value>com/goodstart/core/security/model/hbm/Department.hbm.xml</value>

<value>com/goodstart/oa/casemanager/vo/Casetype.hbm.xml</value>
<value>com/goodstart/oa/casemanager/vo/Tcase.hbm.xml</value>
<value>com/goodstart/oa/casemanager/vo/CaseAttach.hbm.xml</value>
<value>com/goodstart/oa/casemanager/vo/CaseDpm.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${proxool.dialect}</prop>
<prop key="hibernate.show_sql">${proxool.show_sql}</prop>
<prop key="hibernate.cache.use_query_cache">${proxool.cache.use_query_cache}</prop>
  相关解决方案