情况是这样的,我使用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天还未出现以前的错误,应该是算解决了,呵呵,等待更长时间的测试。
分享到:
相关推荐
java.sql.SQLException: 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK ……
NULL 博文链接:https://listen-raining.iteye.com/blog/1962065
服务器出现java.sql.SQLException No suitable driver found for 的
在oracle里面运行一下,解决Exception java.sql.SQLException ORA-00600 内部错误代码
NULL 博文链接:https://zhang-zling.iteye.com/blog/980488
mysql5.6连接驱动jaf,可处理报错java.sql.SQLException: No suitable driver
本文主要介绍了关于MySQL存储表情报错:java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x92\xA9\x0D\x0A…’的相关解决方法,分享出供大家参考学习,下面话不多说了,来一起看看详细的介绍: ...
java.sql.SQLException: null, message from server: “Host ‘223.72.41.7’ is not allowed to connect to this MySQL server” 客户端访问时报错: 解决方法: 1,登陆服务器 mysql> use mysql; //用mysql ...
oracle ora-各种常见java.sql.SQLException归纳
Q: I am working with ... I am using updateBinaryStream method of resultset to update the BLOB field but it is failing after giving following exception java.sql.SQLException: Internal Error: Unable to
主要给大家介绍了关于MySQL存储表情时报错:java.sql.SQLException: Incorrect string value: 'xF0x9Fx92xA9x0Dx0A...'的解决方法,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。
java.sql.SQLException: Operation not allowed after ResultSet closed java.sql.SQLException: QueryRunner requires a DataSource to be invoked in this way, or a Connection should be passed in
异常错误:java.sql.SQLException: The server time zone value ‘?й???’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTime...
oracle 10g 数据库驱动下载:oracle jdbc dirver
问题是这样的…我在VS2008直接运行打开网页,可以连接... 异常详细信息: System.Data.SqlClient.SqlException: 无法打开登录所请求的数据库 “TakeClass”。登录失败。 用户 ‘2D2727E2578F446\ASPNET’ 登录失败。
该用户与可信 SQL Server 连接无关联。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient....
绝对好用的9i驱动包+10g驱动包 解决java.sql.SQLException: 不支持的特性 解决oracle.jdbc.driver.OracleDatabaseMetaData.supportsGetGeneratedKeys()Z异常 等等
Caused by: java.sql.SQLException: java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver at com.trs.gateway.commons.hive.HiveFeature.getConnection(HiveFeature.java:57) at ...