Java结果集以关闭,SQLException:此结果集已关闭

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+"'");

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值