如何避免 Java 中的 ResultSet is closed 异常? [英] How can I avoid ResultSet is closed exception in Java?

查看:25
本文介绍了如何避免 Java 中的 ResultSet is closed 异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我的代码到达我的 while(rs.next()) 循环,它就会产生 ResultSet is closed 异常.导致此异常的原因是什么,我该如何纠正?

As soon as my code gets to my while(rs.next()) loop it produces the ResultSet is closed exception. What causes this exception and how can I correct for it?

我注意到我在我的代码中嵌套了 while(rs.next()) 循环和另一个 (rs2.next()),两个结果集都来自同一个数据库,这是一个问题吗?

I notice in my code that I am nesting while(rs.next()) loop with another (rs2.next()), both result sets coming from the same DB, is this an issue?

推荐答案

听起来像是在遍历第一条语句的结果集之前在同一连接中执行了另一条语句.如果您嵌套处理来自同一数据库的两个结果集,那么您就做错了.这些集合的组合应该在数据库端完成.

Sounds like you executed another statement in the same connection before traversing the result set from the first statement. If you're nesting the processing of two result sets from the same database, you're doing something wrong. The combination of those sets should be done on the database side.

这篇关于如何避免 Java 中的 ResultSet is closed 异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆