java.sql.SQLException: No operations allowed after

情况是这样的,我使用tomcat5.0.28+hibernate2+mysql4,在M$的系统下没出现过任何问题,但将系统装到linux上以后(redhat9及as3),发现过一段时间后就没有办法连接上数据库,查看日志,内容如下:
ERROR http-8080-Processor22 net.sf.hibernate.util.JDBCExceptionReporter - Could not execute query
java.sql.SQLException: No operations allowed after connection closed.


Connection was closed due to the following exception:


** BEGIN NESTED EXCEPTION **


java.sql.SQLException
MESSAGE: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream


** BEGIN NESTED EXCEPTION **


java.io.IOException
MESSAGE: Unexpected end of input stream


STACKTRACE:


java.io.IOException: Unexpected end of input stream
        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1405)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1775)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1109)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2030)
        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1563)
        at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
        at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
        at net.sf.hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:848)
        at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1601)
        at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:27)
省略...........



后来发现,原来是长时间不用这个连接后,JDBC会自动将连接释放,然后就无法连接上,只有重新启动tomcat方可解决,查找资料后,发现如下方法可以解决此问题。


使用hibernate:
<property name="connection.autoReconnect">true</property>  <!--这个是最主要的-->
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
加入以上property,可解决此问题,如果未使用hibernate等持久化管理框架,可在mysql的url中加入autoReconnect=true,这样就可以解决。



mysql的站点上说是JDBC3.1.0-alpha及以前版本会出现此问题,推荐下载新的JDBC驱动,无所谓了,只要能解决问题,我也懒的换,至少现在运行了1天还未出现以前的错误,应该是算解决了,呵呵,等待更长时间的测试。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值