异常问题:No operations allowed after connection closed.
来源:互联网 发布:反转链表 非递归 java 编辑:程序博客网 时间:2024/05/24 07:44
关于com.MySQL.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
意思很明显:连接已经关闭,无法再访问数据库
具体原因我还说不清楚(有人说是因为静态方法获取连接引起的),DBUtil的代码是这样的:
意思很明显:连接已经关闭,无法再访问数据库
具体原因我还说不清楚(有人说是因为静态方法获取连接引起的),DBUtil的代码是这样的:
public class DBUtil { private static final String driver = "com.mysql.jdbc.Driver";// 数据库驱动 private static final String url = "jdbc:mysql://localhost:3306/myproject01?useUnicode=true&characterEncoding=UTF-8";// 连接数据库的URL地址,同时设置字符集编码 private static final String username = "root";// 数据库的用户名 private static final String password = "root";// 数据库的密码 // 创建数据库连接对象 private static Connection conn = null; // 静态代码块负责加载驱动 static { try { Class.forName(driver);// 加载驱动 } catch (Exception ex) { ex.printStackTrace(); } } // 单例模式返回数据库连接对象 public static Connection getConnection() throws Exception { if (conn == null) { conn = DriverManager.getConnection(url, username, password); return conn; } return conn; } }
我的解决办法是这样的:
try { conn = DBUtil.getConnection(); psmt = conn.prepareStatement(sql); psmt.setString(1, eName); psmt.setString(2, ePassword); rs = psmt.executeQuery(); while (rs.next()) { employee.seteId(rs.getInt("e_id")); employee.seteName(rs.getString("e_name")); employee.seteSex(rs.getString("e_sex")); employee.seteBirthday(rs.getDate("e_birthday")); employee.setePhone(rs.getString("e_phone")); employee.setePlace(rs.getString("e_place")); employee.setePassword(rs.getString("e_password")); employee.seteJoinTime(rs.getDate("e_jointime")); employee.seteIsLead(rs.getBoolean("e_islead")); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { // if (conn != null) { // conn.close(); // } if (psmt != null) { psmt.close(); } if (rs != null) { rs.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
不要关闭数据库连接,及把// if (conn != null) { // conn.close(); // } 去掉就可以了
0 0
- 异常问题: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问题
- 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
- myBatis连接MySQL报异常:No operations allowed after connection closed.Connection was implicitly closed
- myBatis连接MySQL报异常:No operations allowed after connection closed.Connection was i
- nutz连接mysql异常处理:MySQLNonTransientConnectionException: No operations allowed after connection closed
- 连接mysql异常处理:MySQLNonTransientConnectionException: No operations allowed after connection closed
- JDBC中No operations allowed after connection closed
- Thinkphp3.2 中的where条件复杂条件下的条件组合
- oracle 更新字段为null hibernate 报错 类型不存在 16 invalid column type 16
- JS原生代码实现鼠标移动图片随之移动效果(另加点击改变图片效果)
- 物理地址、虚拟地址、逻辑地址、线性地址、虚拟内存
- 第四届 山东省ACM SDUT 2607 Mountain Subsequences(LIS+哈希 OR 线段树 待解决)
- 异常问题:No operations allowed after connection closed.
- 身份证验证js
- ros, python初识
- Java 怎样修改文本文件内容
- MyBatis--关联关系查询--多对一--多表连接查询
- python常见数据处理方法
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 2)【solved:12 / 13】
- PYTHON
- 大数据+互联网金融时代,“可以融资的BI”强势来袭!