JDBC中No operations allowed after connection closed
来源:互联网 发布:在国内名校就读 知乎 编辑:程序博客网 时间:2024/05/22 08:11
整理自csdn论坛,点击这里看原帖
第一次调用此方法没问题 可第二次就出现下面的问题(与数据库相关的操作,比如插入,查询等)
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException:
No operations allowed after connection closed
这个问题怎么解决啊 只有把Dao.close();这个关闭Connection的方法去掉,可是这样好像也不对啊?
各位有没有碰到过类似的问题,有好的解决办法?
答案:
原因很简单。在对数据库操作结束后关闭连接是正确的做法,没什么大问题。至于出现:No operations allowed after connection closed。这样的问题原因只有一个,你这里和数据库的连接Connection是一个Static的,程序共享这一个Connection。所以第一次对数据库操作没问题,当把Connection关闭后,第二次还想操作数据库时Connection肯定不存在了。
我本人确实是这个问题,我把connection写成静态全局了,然后第一次调用之后直接关闭了,导致全局关闭了,只要把connection写成局部变量就可以了
0 0
- JDBC中No operations allowed after connection closed
- No operations allowed after connection closed 错误
- solr no operations allowed after connection closed
- No operations allowed after connection closed
- Struts.......No operations allowed after connection closed.
- MySQLNonTransientConnectionException: No operations allowed after connection closed.
- No operations allowed after connection closed. 解决办法
- 问题:No operations allowed after connection closed.
- No operations allowed after connection closed
- No operations allowed after connection closed
- No operations allowed after connection closed异常的解决
- 关于 No operations allowed after connection closed.错误
- MyBatis连接MySQL出错:No operations allowed after connection closed
- 关于 No operations allowed after connection closed.错误
- 异常问题:No operations allowed after connection closed.
- MyBatis异常:No operations allowed after connection closed
- 关于 No operations allowed after connection closed问题
- MySQL: No operations allowed after connection closed。解决办法
- CocoaPods简单使用
- 使用 Cordova(PhoneGap)构建Android程序
- 悟空学Linux专栏----第26篇
- PHP中的异常处理
- Android中如何解析XML数据
- JDBC中No operations allowed after connection closed
- Notepad++调试运行Python脚本方法
- AndroidManifest中android:exported="false"
- MyEclipse 打开Struts配置文件时出错
- GetPrivateProfileString函数--INI配置文件
- Remove Linked List Elements
- 捷登为理芙宝品牌设计的视觉识别系统
- 数据库的最简单实现
- PAT 数据结构 01-复杂度2. Maximum Subsequence Sum (25)