简体   繁体   English

在while(rset.next)内调用方法时用尽的结果集

[英]Exhausted Resultset when calling a method inside the while(rset.next)

I'm getting an Exhausted resultset form the following code. 我从下面的代码中得到一个用尽的结果集。

I've tried a few different things now and can't find a solution, 我已经尝试了几种不同的方法,但找不到解决方案,
if I don't call the songs method it works, but the songs method works when it's called, can't get my head around it, hoping I'm missing something simple. 如果我不调用songs方法,它会起作用,但是当调用它时,songs方法会起作用,无法理解,希望我错过了一些简单的方法。

public void refreshList() {

    rset = po.getProduct();

    if (plist.size() > 0) {
        for (int i = plist.size() - 1; i >= 0; i--) {
            plist.remove(i);
        }
    }
    try {
        while (rset.next()) {

            songs(rset.getString(1));
            CD c = new CD(alist);

            Product p = new Product(rset.getString(1), 
                    rset.getString(2),
                    rset.getString(3), 
                    rset.getDouble(4), 
                    rset.getDouble(5), 
                    rset.getInt(6),
                    rset.getString(7),
                    rset.getString(8),
                    rset.getString(9), 
                    rset.getDouble(10), c);
            plist.add(p);

        }
    } catch (Exception ex) {
        System.out.println(ex);
    }
}


  public void songs(String ID)
{
    rset = po.getSongs();
    alist = new ArrayList<Song>();
    try {
        while (rset.next()){
            Song s = new Song(rset.getString(1),
                    rset.getString(2), 
                    rset.getString(3));
            slist.add(s);
        }   
    } 
    catch (Exception ea) {
        System.out.println(ea);
    }

    for(int i = 0; i < slist.size(); i++)
    {
        if(slist.get(i).getSong_id().equals(ID))
        {
            alist.add(slist.get(i));
        }
    }
}

Inside refreshList you have while (rset.next()) loop, on each iteration of it you have songs(rset.getString(1)); refreshList您有while (rset.next())循环,每次循环时都有songs(rset.getString(1)); , which itself has while(rset.next() . This leads to result set exhaustion, because when you return from songs() you try to take some more data from the current position of result set, while in songs() you got out of while (rset.next()) loop, ie retrieved all its rows. Consider refactoring your code to avoid nested loops based on result set. ,它本身具有while(rset.next() ,这会导致结果集用尽,因为当您从songs()返回时,您尝试从结果集的当前position获取更多数据,而在songs()却退出了while (rset.next())循环,即检索其所有行,请考虑重构代码以避免基于结果集的嵌套循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM