当前位置: 代码迷 >> Java Web开发 >> Connections could not be acquired from the underlying database异常
  详细解决方案

Connections could not be acquired from the underlying database异常

热度:702   发布时间:2016-04-17 01:05:31.0
Connections could not be acquired from the underlying database错误
查询几次后就出现这个问题了,我的配置文件为:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/huyue
</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">HuYue</property>
<property name="hibernate.c3p0.min_size">8</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">120</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">120</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<mapping resource="Forms/Cars.hbm.xml" />
<mapping resource="Forms/Commits.hbm.xml" />
<mapping resource="Forms/Companys.hbm.xml" />
<mapping resource="Forms/Drivers.hbm.xml" />
<mapping resource="Forms/Guides.hbm.xml" />
<mapping resource="Forms/Lines.hbm.xml" />
<mapping resource="Forms/Roads.hbm.xml" />
<mapping resource="Forms/Salestations.hbm.xml" />
<mapping resource="Forms/Startgroup.hbm.xml" />
<mapping resource="Forms/Stations.hbm.xml" />
<mapping resource="Forms/Users.hbm.xml" />

</session-factory>

</hibernate-configuration>
要怎么解决啊,在线等了,高分。

------解决方案--------------------
将数据库服务重启一下,可能是连接数太多了
------解决方案--------------------
你有的地方session没有关闭,造成连接泄漏,最后达到了连接池的最大连接数
------解决方案--------------------
LZ参考下吧,他的错误跟你很类似

http://topic.csdn.net/u/20080904/11/cf9614c5-d47b-4335-8dab-589b517ea0fb.html

http://hi.baidu.com/kingtoon_go/blog/item/421076f042aa52c57831aa67.html
------解决方案--------------------
应该是有什么地方Session没关闭,造成连接数超过最大限制
------解决方案--------------------
最好还是关闭好,一旦你Session对象创建多的话,就有可能造成异常的。。
------解决方案--------------------
在web.xml中配置一个由spring管理的过滤器即可:
 <filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
可在表示层打开session,执行完操作后会自动关闭session

------解决方案--------------------
  相关解决方案