mySql错误: java.sql.SQLException: Operation not allowed after ResultSet closed
2011-12-25 11:53
751 查看
public static int getCheckUsers(List<User> users,String sql) { String sqlQuery = "SELECT COUNT(*) " + sql ; String sqlCol = "SELECT * " + sql ; int totalRecords = -1; Connection conn = DB.getConn() ; Statement stmt = DB.getStatement(conn); // 一个状态。打开获得查询个数的结果集 ResultSet rsCount = DB.getResultSet(stmt, sqlQuery); // 得到总个数 PreparedStatement pstmtUser = DB.prepare(conn, sqlCol); // 另一个状态,获得符合条件的结果集 ResultSet rs = DB.getResultSet(pstmtUser, sqlCol); // 得到所有用户的集合 try { rsCount.next(); totalRecords = rsCount.getInt(1); DB.close(rsCount); while(rs.next()) { User u = new User(); u.setId(rs.getInt("id")); u.setUsername(rs.getString("username")); u.setPassword(rs.getString("password")); u.setPhone(rs.getString("phone")); u.setAddr(rs.getString("addr")); u.setRdate(rs.getTimestamp("rdate")); users.add(u); } } catch (SQLException e) { e.printStackTrace(); }finally { DB.close(conn); DB.close(rs); DB.close(pstmtUser); } return totalRecords ; }
代码如上:获得的结果集的状态必须不一样,如果一样的话,每次只能操作一个,所以必定导致另一个关闭。本代码是用的两个不同的状态。Statement 和 PreparedStatement.
相关文章推荐
- java.sql.SQLException: Operation not allowed after ResultSet closed
- Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
- java.sql.SQLException: Operation not allowed after ResultSet closed
- MySQL 错误:Operation not allowed after ResultSet closed
- mysql错误:Operation not allowed after ResultSet closed
- 关于Operation not allowed after ResultSet closed错误的一种解决方式
- Java学习笔记:Exception:Operation not allowed after ResultSet closed
- 数据库操作错误之“Operation not allowed after ResultSet closed”
- Operation not allowed after ResultSet closed 错误的解决方案
- Operation not allowed after ResultSet closed--Mysql
- 错误:Operation not allowed after ResultSet closed
- operation not allowed after resultset closed错误的解决
- 错误:Operation not allowed after ResultSet closed
- java.sql.SQLException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exceptio
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQL server"
- Operation not allowed after ResultSet closed
- Operation not allowed after ResultSet closed--操作mysql数据库
- 远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- Operation not allowed after ResultSet closed--操作mysql数据库
- SQLExecption:Operation not allowed after ResultSet closed解决办法