同时打开两个结果集 [英] Open two resultsets simultaneously

查看:97
本文介绍了同时打开两个结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这样做:

while (rs.next()) {
    int id = rs.getInt(1);

    ResultSet innerRs = stmt.executeQuery("select something from sometable where id =" + id + ";");

    String one = innerRs.getString(1);
    String two = rs.getString(2);    //result set is already closed thrown here. 

}

但是我收到错误消息结果集已经关闭".我正在使用Postgresql.我真的不知道另一种方法不是很费力.我该如何解决这个错误?

but I am getting the error "result set already closed". I am using Postgresql. I can't really figure out another way to do this that isn't very labour intensive. How can I get around this error?

推荐答案

您不需要两个结果集.只需学习 SQL JOIN子句,以便您可以在单个SQL查询中从两个不同的表中获取所需的数据.

You don't need two resultsets. Just learn the SQL JOIN clause so that you can get the desired data from two different tables in a single SQL query.

如果确实需要,那么创建一条单独的语句而不是重用现有的语句确实是一种方法.重新使用它会强制关闭所有先前打开的游标(结果集).

If you really need to, then creating a separate statement instead of reusing an existing one is indeed the way to go. Reusing it would namely force all previously opened cursors (resultsets) to be closed.

这篇关于同时打开两个结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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