Tomcat+Hibernate长时间不访问之后,访问WEB系统时Tomcat报错
再就是如果数据库断了后,TOMCAT没办法自动重新连接数据库
我应该怎么解决?谢谢大家
<?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 ">
<hibernate-configuration>
<session-factory>
<property name= "hibernate.connection.url "> jdbc:mysql://20.20.20.6:3306/tcs?useUnicode=true&characterEncoding=UTF-8 </property>
<property name= "hibernate.connection.driver_class "> com.mysql.jdbc.Driver </property>
<property name= "hibernate.connection.username "> root </property>
<property name= "hibernate.connection.password "> 123123 </property>
<property name= "hibernate.show_sql "> false </property>
<property name= "hibernate.dialect "> org.hibernate.dialect.MySQLInnoDBDialect </property>
<!-- Mapping files -->
<mapping resource= "com/tcs/bean/entitybean/TestRecord.hbm.xml " />
<mapping resource= "com/tcs/bean/entitybean/StaticAnalyse.hbm.xml " />
</session-factory>
</hibernate-configuration>
------解决方案--------------------报什么错误?
数据库断了,tomcat当然没办法自动重新连接,你要重新启动tomcat才能解决.
------解决方案--------------------使用Hibernate+proxool解决问题,这是我浏览网页时发现的,我没用过,不知道是否可以。我已经将它里面的一些数据库连接,用户名和密码改成楼主的了,楼主可以试试。
由于数据库connection在较长时间没有访问下会自动断开连接,导致浏览出错,增加proxool作为数据库pool。它有自动连接功能。
1、从http://proxool.sourceforge.Net/下载proxool,释放proxool.jar到WEB-INF/lib
2、在hibernate.cfg.Xml中增加:
<property name= "hibernate.proxool.pool_alias "> dbpool </property>
<property name= "hibernate.proxool.xml "> proxool.xml </property>
<property name= "connection.provider_class "> org.hibernate.connection.ProxoolConnectionProvider </property>
3、在与hibernate.cfg.xml同级目录(src根目录下)增加proxool.Xml文件:
<?Xml version= "1.0 " encoding= "utf-8 "?>
<!-- the proxool configuration can be embedded within your own application 's.
Anything outside the "proxool " tag is ignored. -->
<something-else-entirely>
<proxool>
<alias> dbpool </alias>
<!--proxool只能管理由自己产生的连接-->
<driver-url>
jdbc:mysql://20.20.20.6:3306/tcs?useUnicode=true&characterEncoding=UTF-8
</driver-url>
<driver-class> com.mysql.jdbc.Driver </driver-class>
<driver-properties>
<property name= "user " value= "root " />
<property name= "password " value= "123123 " />
</driver-properties>
<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁-->
<house-keeping-sleep-time> 90000 </house-keeping-sleep-time>
<!-- 最少保持的空闲连接数-->
<prototype-count> 5 </prototype-count>
<!-- 允许最大连接数,超过了