数据库连接长时间空闲后,爆连接已经关闭的解决方法
2011-12-02 16:41
218 查看
<p style="">在很多场合都碰到有人提问: 第二天第一次访问应用,总是报连接已经关闭(Connection Close)
<p style=""><a style="color: #2970a6; text-decoration: none;" href="http://commons.apache.org/dbcp/api-1.4/org/apache/commons/dbcp/BasicDataSource.html" target="_blank">Apache DBCP</a>:
<div class="wp_codebox_msgheader" style="">
<span class="left" style="padding-bottom: 2px; line-height: 18px; padding-left: 20px; padding-right: 5px; font-family: tahoma, arial, verdana; background-position: 0% 50%; float: left; margin-left: 5px; font-size: 14px; margin-right: 10px; padding-top: 2px;"><a style="color: #2970a6; font-weight: bold; text-decoration: none;">View Code</a><span class="Apple-converted-space"> </span>JAVA</span>
<div class="wp_codebox" style="">
<table style="border-bottom: #cccccc 2px solid; border-left: #cccccc 2px solid; background-color: #ffffff; margin: 5px 0px 10px; width: 586px; border-collapse: collapse; border-top: #cccccc 2px solid; border-right: #cccccc 2px solid;" border="0"><tbody><tr id="p3091">
<td id="p309code1" class="code" style="border-bottom: #cccccc 1px solid; text-align: left; border-left: #cccccc 1px solid; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; vertical-align: top; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 3px;">
</td>
</tr></tbody></table>
<div class="wp_codebox_msgheader" style="">
<span class="left" style="padding-bottom: 2px; line-height: 18px; padding-left: 20px; padding-right: 5px; font-family: tahoma, arial, verdana; background-position: 0% 50%; float: left; margin-left: 5px; font-size: 14px; margin-right: 10px; padding-top: 2px;"><a style="color: #2970a6; font-weight: bold; text-decoration: none;">View Code</a><span class="Apple-converted-space"> </span>JAVA</span>
<div class="wp_codebox" style="">
<table style="border-bottom: #cccccc 2px solid; border-left: #cccccc 2px solid; background-color: #ffffff; margin: 5px 0px 10px; width: 586px; border-collapse: collapse; border-top: #cccccc 2px solid; border-right: #cccccc 2px solid;" border="0"><tbody><tr id="p3092">
<td id="p309code2" class="code" style="border-bottom: #cccccc 1px solid; text-align: left; border-left: #cccccc 1px solid; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; vertical-align: top; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 3px;">
</td>
</tr></tbody></table>
<p style=""><a style="color: #2970a6; text-decoration: none;" href="http://proxool.sourceforge.net/api-dev/org/logicalcobwebs/proxool/ProxoolDataSource.html" target="_blank">Proxool</a>:
<div class="wp_codebox_msgheader" style="">
<span class="left" style="padding-bottom: 2px; line-height: 18px; padding-left: 20px; padding-right: 5px; font-family: tahoma, arial, verdana; background-position: 0% 50%; float: left; margin-left: 5px; font-size: 14px; margin-right: 10px; padding-top: 2px;"><a style="color: #2970a6; font-weight: bold; text-decoration: none;">View Code</a><span class="Apple-converted-space"> </span>JAVA</span>
<div class="wp_codebox" style="">
<table style="border-bottom: #cccccc 2px solid; border-left: #cccccc 2px solid; background-color: #ffffff; margin: 5px 0px 10px; width: 586px; border-collapse: collapse; border-top: #cccccc 2px solid; border-right: #cccccc 2px solid;" border="0"><tbody><tr id="p3093">
<td id="p309code3" class="code" style="border-bottom: #cccccc 1px solid; text-align: left; border-left: #cccccc 1px solid; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; vertical-align: top; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 3px;">
</td>
</tr></tbody></table>
<p style="">其实原来也就这么简单,返回连接给用户之前,先执行一条简单无害快速的SQL 阅读更多
<p style=""><a style="color: #2970a6; text-decoration: none;" href="http://commons.apache.org/dbcp/api-1.4/org/apache/commons/dbcp/BasicDataSource.html" target="_blank">Apache DBCP</a>:
<div class="wp_codebox_msgheader" style="">
<span class="left" style="padding-bottom: 2px; line-height: 18px; padding-left: 20px; padding-right: 5px; font-family: tahoma, arial, verdana; background-position: 0% 50%; float: left; margin-left: 5px; font-size: 14px; margin-right: 10px; padding-top: 2px;"><a style="color: #2970a6; font-weight: bold; text-decoration: none;">View Code</a><span class="Apple-converted-space"> </span>JAVA</span>
<div class="wp_codebox" style="">
<table style="border-bottom: #cccccc 2px solid; border-left: #cccccc 2px solid; background-color: #ffffff; margin: 5px 0px 10px; width: 586px; border-collapse: collapse; border-top: #cccccc 2px solid; border-right: #cccccc 2px solid;" border="0"><tbody><tr id="p3091">
<td id="p309code1" class="code" style="border-bottom: #cccccc 1px solid; text-align: left; border-left: #cccccc 1px solid; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; vertical-align: top; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 3px;">
dataSource.<span style="color: #006633;">setValidationQuery</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'select 1'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
</td>
</tr></tbody></table>
<div class="wp_codebox_msgheader" style="">
<span class="left" style="padding-bottom: 2px; line-height: 18px; padding-left: 20px; padding-right: 5px; font-family: tahoma, arial, verdana; background-position: 0% 50%; float: left; margin-left: 5px; font-size: 14px; margin-right: 10px; padding-top: 2px;"><a style="color: #2970a6; font-weight: bold; text-decoration: none;">View Code</a><span class="Apple-converted-space"> </span>JAVA</span>
<div class="wp_codebox" style="">
<table style="border-bottom: #cccccc 2px solid; border-left: #cccccc 2px solid; background-color: #ffffff; margin: 5px 0px 10px; width: 586px; border-collapse: collapse; border-top: #cccccc 2px solid; border-right: #cccccc 2px solid;" border="0"><tbody><tr id="p3092">
<td id="p309code2" class="code" style="border-bottom: #cccccc 1px solid; text-align: left; border-left: #cccccc 1px solid; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; vertical-align: top; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 3px;">
dataSource.<span style="color: #006633;">setTestConnectionOnCheckout</span><span style="color: #009900;">(</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
dataSource.<span style="color: #006633;">setPreferredTestQuery</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'select 1'</span><span style="color: #009900;">)</span>
</td>
</tr></tbody></table>
<p style=""><a style="color: #2970a6; text-decoration: none;" href="http://proxool.sourceforge.net/api-dev/org/logicalcobwebs/proxool/ProxoolDataSource.html" target="_blank">Proxool</a>:
<div class="wp_codebox_msgheader" style="">
<span class="left" style="padding-bottom: 2px; line-height: 18px; padding-left: 20px; padding-right: 5px; font-family: tahoma, arial, verdana; background-position: 0% 50%; float: left; margin-left: 5px; font-size: 14px; margin-right: 10px; padding-top: 2px;"><a style="color: #2970a6; font-weight: bold; text-decoration: none;">View Code</a><span class="Apple-converted-space"> </span>JAVA</span>
<div class="wp_codebox" style="">
<table style="border-bottom: #cccccc 2px solid; border-left: #cccccc 2px solid; background-color: #ffffff; margin: 5px 0px 10px; width: 586px; border-collapse: collapse; border-top: #cccccc 2px solid; border-right: #cccccc 2px solid;" border="0"><tbody><tr id="p3093">
<td id="p309code3" class="code" style="border-bottom: #cccccc 1px solid; text-align: left; border-left: #cccccc 1px solid; padding-bottom: 3px; padding-left: 10px; padding-right: 10px; vertical-align: top; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 3px;">
dataSource.<span style="color: #006633;">setTestBeforeUse</span><span style="color: #009900;">(</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
dataSource.<span style="color: #006633;">setHouseKeepingTestSql</span><span style="color: #009900;">(</span><span style="color: #0000ff;">'select 1'</span><span style="color: #009900;">)</span>
</td>
</tr></tbody></table>
<p style="">其实原来也就这么简单,返回连接给用户之前,先执行一条简单无害快速的SQL 阅读更多
相关文章推荐
- 数据库连接长时间空闲后,爆连接已经关闭的解决方法
- 嵌入式 mysql_free_version出现长时间不操作会自动关闭连接解决方法(有代码)
- WCF项目中出现常见错误的解决方法:基础连接已经关闭: 连接被意外关闭
- 用httpWebRequest调用https开头的php webservice,报“基础连接已经关闭: 未能为SSL/TLS 安全通道建立信任关系”错误的解决方法
- ORA-00257归档日志写满的解决方法 背景: 在前一篇博客中我们提到了如何启动或关闭oracle的归档(ARCHIVELOG)模式,在我成功设定数据库为归档模式以后, 第二天再次尝试连接数据库,
- WCF项目中出现常见错误的解决方法:基础连接已经关闭: 连接被意外关闭
- 已经连接到空闲例程的解决方法
- 嵌入式 mysql长时间没操作会自动关闭连接default是8hours解决方法集合mysql_ping(可能部分重复)
- webservice 提示远程连接已经关闭的解决方法
- webservice 提示远程连接已经关闭的解决方法
- 基础连接已经关闭:服务器关闭了本应保持活动状态的连接 解决方法
- C#利用HttpWebRequest后台请求,出现:基础连接已经关闭: 接收时发生错误;【解决方法之一】
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- dreamweaver连接数据库典型问题解决方法
- sql server2000+vs2005连接数据库时出错,解决方法
- WindowsXP中用IIS浏览ASP不能连接数据库问题的解决方法
- (转)MySQL5.0中文问题及JDBC数据库连接和JSP汉字编码问题解决方法总结
- PLSQL Developer 连接数据库 弹出空白对话框 解决方法
- 解决TranctionScope调试时关闭数据库连接问题
- ASP.NET在IIS上部署使用Oracle数据库无法连接数据库解决方法(转载)