SQLException:此结果集已关闭

编程入门 行业动态 更新时间:2024-10-21 15:51:28
本文介绍了SQLException:此结果集已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试比较三个 Resultset 中的值,但是似乎有例外,我尝试运行它。 有人可以帮我解决问题所在。我将不胜感激。这是引发错误的代码段:

I am trying to compare values from three Resultset, but there seems to exception wen I try to run it. Could someone help me on where am going wrong. I will appreciate any help. Here's the code snippet that's throwing the error:

java.sql.Connection connDB = null; java.lang.Object[] reconciledPaymentDetails = null; java.util.Vector shiftsVector = new java.util.Vector(1, 1); String status = ""; try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException ex) { Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex); } try { connDB = DriverManager.getConnection("jdbc:postgresql://" + hostName + ":" + portNumber + "/" + dbName, userName, password); System.out.println("Connection established : [" + connDB.toString() + "]"); java.sql.Statement pstmt = connDB.createStatement(); java.sql.Statement pstmtShifts = connDB.createStatement(); java.sql.ResultSet rset = pstmt.executeQuery("SELECT DISTINCT payment_mode, transaction_type, credit FROM ac_cash_collection WHERE shift_no = '" + shiftNumber + "'"); while (rset.next()) { java.sql.ResultSet rsetShifts = pstmtShifts.executeQuery("SELECT DISTINCT amount, shift_amount FROM ac_shift_collections WHERE shift_no = '" + shiftNumber + "' AND pay_mode ilike '"+rset.getString(1) +"'"); while (rsetShifts.next()) { java.sql.ResultSet rset2 = pstmt.executeQuery("select debit from ac_cash_book where shift_no='"+shiftNumber+"'"); while (rset2.next()){ double debit =rset2.getDouble("debit"); if((rset2.getDouble("debit")<=0 )) status = "no_banked"; else if((rset2.getDouble("debit")==rsetShifts.getDouble("amount")) && (rsetShifts.getDouble("amount"))< rsetShifts.getDouble("shift_amount")) status= "BntClosed"; else if (rset2.getDouble(1)==rsetShifts.getDouble("shift_amount")) Status ="bClosed"; shiftsVector.addElement(rset.getString(1)+":"+rsetShifts.getString(1)+":"+status); } } }

推荐答案

java.sql.ResultSet rset = pstmt.executeQuery("SELECT DISTINCT payment_mode, transaction_type, credit FROM ac_cash_collection WHERE shift_no = '" + shiftNumber + "'"); java.sql.ResultSet rset2 = pstmt.executeQuery("select debit from ac_cash_book where shift_no='"+shiftNumber+"'");

第二个调用释放了第一个调用生成的资源,这就是ResultSet被关闭的原因。

Your second call releases the resources generated by the first one, that's why the ResultSet is closed.

更多推荐

SQLException:此结果集已关闭

本文发布于:2023-10-18 10:57:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504034.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQLException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!