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 ...
随机推荐
- PHP学习之-1.4 计算表达式
计算表达式 不同于HTML和CSS,在PHP中做计算,比如我们写 echo 12*3 计算结果是36.代码如下 <?php echo 12*3;?> 实例 <!DOCTYPE HTM ...
- python - Django: Converting an entire set of a Model's objects into a single dictionary - Stack Overflow
python - Django: Converting an entire set of a Model's objects into a single dictionary - Stack Over ...
- Python集成开发环境(Eclipse+Pydev)
刚開始学习python,就用Editplus, Notepad++来写小程序, 后来接触了Sublime Text2.认为很不错,没事写写代码.就用编辑器Sublime Text2,最好再配搭一个ap ...
- TestNg JAVA 自动化单元测试框架Demo
TestNg TestNg 是java的一个自动化单元测试框架 参考:http://testng.org/doc/index.html 环境准备 既然是java 的自动化单元测试框架,就必须要有jav ...
- leetcode Sum Root to Leaf Numbers(所有路径之和)
转载请注明来自souldak,微博:@evagle 观察题目给的返回值类型是int,可以断定这棵树的高度不会超过10,所以数据量其实是非常小的.那就直接dfs遍历这棵树,然后到叶子节点的时候将值加到最 ...
- Lucene之删除索引
1.前言 之前的博客<Lucene全文检索之HelloWorld>已经简单介绍了Lucene的索引生成和检索.本文着重介绍Lucene的索引删除. 2.应用场景: 索引建立完成后,因为有些 ...
- poj1066 Jugs
poj1066 Jugs http://poj.org/problem?id=1606 解题思路:本题可以用数学方法解得,最易理解,常规的解法是搜索.直接用接近模拟的广度优先搜索即可过. 给两个容器, ...
- 从头学起android<AudioManager 声音编辑器.五十.>
我们用android经常使用的时候,手机的声音增大和缩小操作.在设定场景模式,它往往使用静音和振动运行,这通常是AudioManager来控制的. 今天我们就来看一下AudioManager 的使用. ...
- 微信公众平台应用开发框架sophia设计不足(1)
设计一个小框架考虑的东西真不少,每一样都不easy: 1.既要解决当前技术的不足: 2.又要方便他人使用(基本的目的). 3.同一时候又要设计得优雅.easy扩展. sophia一開始设计用来支持智能 ...
- Functional Jobs // Hire Functional Programmers In Less Time
Functional Jobs // Hire Functional Programmers In Less Time Hire Functional Programmers Quick Save T ...