tomcat dbcp 基于jndi当配置java.sql.SQLException: Already closed
最近发现了一个现象,观察到的生产环境,不要有一段时间操作,然后另一个操作,首先将有一个数据库连接:java.sql.SQLException: Already closed.,例如下列:
error log: ( org.springframework.dao.RecoverableDataAccessException: PreparedStatementCallback; SQL [select user_id,login_name from t_sys_user where login_name=?
and password=?]; The last packet successfully received from the server was1290665 seconds ago.The
last packet sent successfully to the server was 1290665 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server
configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server
was1290665 seconds ago.The last packet sent successfully to the server was 1290665 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application,
increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. )
数据源是用tomcat dbcp 基于jndi配置管理的。查了下。例如以下:
原因:
You're probably running into the fact that MYSQL closes connections which have been open "too long".
Probably if you make the request to the server again, you'll find that it works because the connection is reopened.
解决方法:
One way to deal with this is to add the following to your context.xml Resource:
validationQuery="select 1"
(基于mysql)
validationQuery="select
1 from dual" (基于oracle)
代价:
This causes a very cheap test query to always be run first; if the connection has been closed, this gets the failure,
and
then a new connection is opened.
细想下原来用weblogic jdbc jndi的配置有一个专门的配置项来配置这个test query,配置tomcat时粗心大意了 :(
[2015-04-30 11:15:46,939 ERROR [com.tencent.vsuning.aop.LogAdvice] - org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Data source rejected establishment of connection, message from server: "Too many connections"] 数据库连接池耗尽异常...
版权声明:本文博主原创文章,博客,未经同意不得转载。
tomcat dbcp 基于jndi当配置java.sql.SQLException: Already closed的更多相关文章
- Tomcat 5.5 JNDI Resource 配置 (tomcat数据源配置)
转自:http://blog.csdn.net/fenglibing/article/details/4528512 Tomcat 5.5 JNDI Resource 配置 Author Blog:h ...
- java.sql.SQLException: Io 异常: Connection reset
当数据库连接池中的连接被创建而长时间不使用的情况下,该连接会自动回收并失效,但客户端并不知道,在进行数据库操作时仍然使用的是无效的数据库连接,这样,就导致客户端程序报“ java.sql.SQLExc ...
- spring+ibatis问题1—— 程序报错:java.sql.SQLException: Io 异常: Connection reset by peer, socket write error; ”或“java.sql.SQLException 关闭的连接”异常
转自:http://blog.sina.com.cn/s/blog_1549fb0710102whz2.html spring+ibatis程序测试时报错:java.sql.SQLException: ...
- Caused by: java.sql.SQLException: Incorrect integer value: '' for column 'clientId' at row 41
1.错误描述 [ERROR:]2015-06-10 13:48:26,253 [异常拦截] oa.exception.ExceptionHandler org.hibernate.exception. ...
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
1.错误描述 [ERROR:]2015-05-05 16:35:50,664 [异常拦截] org.hibernate.exception.GenericJDBCException: error ex ...
- Caused by: java.sql.SQLException: Operand should contain 1 column(s)
1.错误描述 [ERROR:]2015-05-05 15:48:55,847 [异常拦截] org.hibernate.exception.DataException: error executing ...
- maven+springmvc出现:java.sql.SQLException: Unknown system variable 'query_cache_size'
连接mysql时一直出现以下的错误: org.springframework.web.util.NestedServletException: Request processing failed; n ...
- JavaWeb:c3p0配置问题-----java.sql.SQLException: Connections could not be acquired from the underlying database!
错误原因 c3p0的配置错误 错误显示 -classpath "D:\Program\Software\IntelliJIDEA\IntelliJ IDEA 2018.2.5\lib\ide ...
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB3' for column 'Content' at row 1
在尝试将 emoji 表情符号 插入MySQL数据库时,遇到以下错误信息: ### The error occurred while setting parameters ### SQL: INSER ...
随机推荐
- js正则验证手机号码有效性
验证130-139,150-159,180-189号码段的手机号码 <script type="text/javascript"> [-]{})|([-]{})|([- ...
- Delete it
Problem A: Delete it Time Limit: 2 Sec Memory Limit: 64 MB Submit: 99 Solved: 25 Description 克林在 ...
- HDU4549 M斐波那契数
M斐波那契数列 题目分析: M斐波那契数列F[n]是一种整数数列,它的定义例如以下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 如今给 ...
- abap优化工具事务代码: ST05
- frame.bounds和center
CGPoint point=CGPoint(x,y); //表示位置 CGSize size=CGSzieMake(width,height); //表示大小 CGRect rect=CGRect ...
- 大数据时代的精准数据挖掘——使用R语言
老师简介: Gino老师,即将步入不惑之年,早年获得名校数学与应用数学专业学士和统计学专业硕士,有海外学习和工作的经历,近二十年来一直进行着数据分析的理论和实践,数学.统计和计算机功底强悍. 曾在某一 ...
- Python标准库:内置函数dict(iterable, **kwarg)
本函数是从可迭代对象来创建新字典.比方一个元组组成的列表,或者一个字典对象. 样例: #dict() #以键对方式构造字典 d1 = dict(one = 1, two = 2, a = 3) pri ...
- 每天一个JavaScript实例-推断图片是否载入完毕
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- 【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
一.对UITabBar背景和icon图标的一些设置 (1)由于直接给UITabBar设置的背景颜色显示的不纯.半透明的感觉,所以,有时候我们能够直接利用纯色的图片作为背景达到想要的效果. (2)给ic ...
- c++ 类名和enum时重复时要在类名前加class::
c++ 类名和enum时重复时要在类名前加class:: 一些不好的习惯都是用小写,但又没有区分开token,看看代码再说,下面的代码是我在测试polymorphism时写的一部分,怎么也查不出,最后 ...