如何防止ResultSet在Connection关闭时失效? [英] How to prevent a ResultSet from being invalidated on Connection close?

查看:486
本文介绍了如何防止ResultSet在Connection关闭时失效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从执行查询并关闭连接的函数传递一个结果集。



但是,一旦其父对象连接已关闭并抛出

  java.sql.SQLException:ResultSet关闭后不允许操作
解决方案

你不能。如果你想得到所有的数据,循环 ResultSet 并插入数据到你的集合。



请查看 commons-dbutils - 它有很多有用的帮助者。


I'd like to pass out a result set from a function that executes a query and closes the connection.

But the ResultSet gets invalidated as soon as its parent Connection is closed and throws

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

How to avoid this?

解决方案

You can't. If you want to get all the data, loop the ResultSet and insert the data into a collection of yours.

Take a look at commons-dbutils - it has a lot of useful helpers.

这篇关于如何防止ResultSet在Connection关闭时失效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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