java.sql.SQLException: 关闭的 Resultset: next

根据异常信息判断是数据库查询出来的结果集被关闭了,所以就了next

我的代码是一个Impl方法(假设为A方法)中调用另一个Impl方法(假设为B方法),我在执行完B方法后,调用了一下关闭数据库连接的方法,结果把A方法连接数据库给关闭了;

解决方法是把B方法中 关闭数据库连接的方法(即:super.close(con, pstmt, null, rs);)给删除了!

下面是我的出错误的代码:

/**
* 查询延期的任务
*/
@Override
public List<Extension> findPlanTask(String itemId) {
con = super.getConnection();
List<Extension> planTaskList=new ArrayList<Extension>();
Extension extension=null;
String sql="select yq_yjtzrq,yq_rwbh from qj_extension where yq_xmbh=?";
try{
pstmt=con.prepareStatement(sql);
pstmt.setString(1, itemId);
rs=pstmt.executeQuery();
while(rs.next()){

extension=new Extension();
extension.setYjtzrq(rs.getString("yq_yjtzrq"));
PlanTask plantask= selectPlantask(rs.getString("yq_rwbh"));
extension.setPlanTask(plantask);
planTaskList.add(extension);
}
}catch (SQLException e) {
e.printStackTrace();
}
super.close(con, pstmt, null, rs);
return planTaskList;
}

/**
* 根据延期计划的id查询任务
* @param pid
* @return
*/
private PlanTask selectPlantask(String pid) {
con = super.getConnection();
PlanTask planTask=null;
String sql="select planTask_rwbh,planTask_Rwzt,planTask_Rwjc,planTask_Jcms,planTask_Rwlb,planTask_Rwmc,planTask_Jhksrq,planTask_Jhwcrq from qj_plantask where planTask_jhbh=?";
try{
pstmt=con.prepareStatement(sql);
pstmt.setString(1, pid);
rs=pstmt.executeQuery();
while(rs.next()){
planTask=new PlanTask();
planTask.setPlanTaskRwbh(rs.getString("planTask_rwbh"));
planTask.setPlanTaskRwzt(rs.getString("planTask_Rwzt"));
planTask.setPlanTaskRwjc(rs.getInt("planTask_Rwjc"));
planTask.setPlanTaskJcms(rs.getString("planTask_Jcms"));
planTask.setPlanTaskRwlb(rs.getString("planTask_Rwlb"));
planTask.setPlanTaskRwmc(rs.getString("planTask_Rwmc"));
planTask.setPlanTaskJhksrq(rs.getString("planTask_Jhksrq"));
planTask.setPlanTaskJhwcrq(rs.getString("planTask_Jhwcrq"));
}
}catch (SQLException e) {
e.printStackTrace();
}

super.close(con, pstmt, null, rs);
return planTask;
}

时间: 2024-10-13 14:27:31

java.sql.SQLException: 关闭的 Resultset: next的相关文章

java.sql.SQLException: 关闭的连接 解决办法

程序如果长时间不进行数据库操作,那么数据源中的 Connection 很可能已经断开.其原因有可能是防火墙,或者连接的数据库设置的超时时间.这里使用的是 C3P0 连接 oracle 数据库,引起的异常信息为: org.springframework.transaction.TransactionSystemException: Could not roll back Hibernate transaction; nested exception is org.hibernate.Transac

mybatis oracle java.sql.SQLException: 流已被关闭问题

/** * 按照页码取值(从current_page页开始,每页page_size条) * @param key * @param params * @param current_page * @param page_size * @return */ public <T> Pagination getPaginationByPage(String key, Object params,int current_page,int page_size) { int count = (Integer

java.sql.SQLException: Operation not allowed after ResultSet closed

转自:http://blog.csdn.net/hellobobantang/article/details/7173622 java.sql.SQLException: Operation not allowed after ResultSet closedat com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)at com.mysql.jdbc.SQLError.createSQLException(SQLError.

Caused by: java.sql.SQLException: ResultSet is from UPDATE. No Data.

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql

resultset 对象获取行字段数据时报:java.sql.SQLException: Column &#39;id&#39; not found.

resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found. 代码: String sql="SELECT d.content,c.name AS categoryName FROM news_detail d,news_category c WHERE d.categoryId=c.id"; Object[] params ={}; System.out.println(this.executeQuery(sq

java中mysql查询报错java.sql.SQLException: Before start of result set

异常:java.sql.SQLException: Before start of result set 解决方法:使用rs.getString();前一定要加上rs.next(); sm = conn.createStatement(); ResultSet rs = null; String sql_max = "SELECT id FROM a WHERE name= '" + name + "' ORDER BY online_time DESC LIMIT 1&qu

Cause: java.sql.SQLException: 无法转换为内部表示(Mybatis)

公司开发档案系统使用框架:Spring+Struts2+Mybatis+EasyUI,在开发过程中出现sql异常:“Cause: java.sql.SQLException: 无法转换为内部表示”,错误如下: org.springframework.jdbc.UncategorizedSQLException: ### Error querying database. Cause: java.sql.SQLException: 无法转换为内部表示 ### The error may involv

java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect

java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect 2014年06月29日 ⁄ 综合 ⁄ 共 637字 ⁄ 字号 小 中 大 ⁄ 评论关闭 java.sql.SQLException: null,  message from server: "Host 'xxx' is not allowed to connect to this MySQL server": j

java.sql.SQLException: Can not issue empty query.

1.错误叙述性说明 java.sql.SQLException: Can not issue empty query. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java: