JDBC异常:ResultSet关闭后不允许操作 [英] JDBC Exception: Operation not allowed after ResultSet closed

查看:282
本文介绍了JDBC异常:ResultSet关闭后不允许操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

获取java.sql.SQLException:ResultSet关闭后不允许操作

我正在处理一些正在抛出的代码 ResultSet关闭后不允许操作异常。这里是:

I'm working on some code that is throwing Operation not allowed after ResultSet closed exceptions. Here it is:

ResultSet res = stmt.executeQuery("SELECT codigo FROM projecto WHERE nome='"
    + auxiliarNomes.elementAt(i).toString() + "'");
while (res.next()) {
    codigo = res.getString("codigo");
    stmt.executeUpdate("insert into categoriaprojectos values("
        + "'" + codigo + "'" + "," + "'" + Antena.RetornaCodigoProjecto() + "')");
}

我做错了什么?

推荐答案

这是可能的。只需使用一个额外的连接和语句。

This is possible. Just use an extra connection and statement.

Statement statementOne = connectionOne.createStatement();
Statement statementTwo = connectionTwo.createStatement();
ResultSet resultSetOne = statementOne.executeQuery("select * from x");

while (resultSetOne.next()) {
    ResultSet resultSetTwo = statementTwo.executeQuery(String.format("select * from y where xy = %s", resultSetOne.getString(0)));

    while (resultSetTwo.next()) {
        String result = resultSetTwo.getString(0);
    }
}

这篇关于JDBC异常:ResultSet关闭后不允许操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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