4

我正在做一个简单的查询,我知道它很好并且在语法上是正确的(执行它时没有发现异常并ResultSet返回)。

但是,当我将此结果集传递给一个方法以循环遍历它并执行一些操作时,程序会在此结果集中的第一行(无限循环)中卡住循环。我真的无法弄清楚这个问题可能是什么。如果查询很好,则ResultSet结果正确(我无法通过调试看到其中的内容,但它应该是正确的)那么可能是什么问题?

这是更好地了解我正在做的事情的代码。

ResultSet rs3 = null;

if (linked == J.LINKED_TO_ORG) {
    Vector<Integer> linkedTicketIds = new Vector<Integer>();

    while (rs.next()){
        // returns a set of id's for linked tickets
        Vector<Integer> linkedToTicket = Ticket.get_linked_OrgTickets(con, rs.getInt(Ticket.FLD_ID)); 

        if (!linkedToTicket.isEmpty()) {                                
            // if there are linked tickets in the result set, add them to vector
            // so they can be outputted alone
            linkedTicketIds.add(rs.getInt(Ticket.FLD_ID));
        }
    }

    if (!linkedTicketIds.isEmpty()){
        rs3 = select_linked_or_unlinked(con, linkedTicketIds, select_from);                 
    }
} 

select_linked_or_unlinked方法中,以下查询是使用字符串缓冲区和返回良好结果的向量 linkedTicketIds 构建的(添加格式以提高可读性):

SELECT Tick.ID
     , Tick.DESCRIPTION
     , Tick.TICKETTYPE
     , States.SHORT_NAME as state
     , Pri.DESCRIPTION   as priority
     , Owners.Login      as Owner
     , Submitters.Login  as Submitter
     , types.SHORT_NAME  as type
     , Tick.TITLE
     , Proj.Name         as Project
     , Proj.ID
     , Tick.RELEASE_NUM  as Release
     , Tick.SUBMIT_DATE
     , Tick.CUSTOMER
     , rownumber() OVER (ORDER BY Pri.ZORDER DESC)
                         as ROW_NEXT   
  FROM HOBTRACK.Tickets_Customers_View Tick
     , HOBTRACK.PROJECTS               Proj
     , HOBTRACK.PRIORITIES             Pri
     , HOBTRACK.STATES                 States
     , HOBTRACK.USERS                  Owners
     , HOBTRACK.USERS                  Submitters
     , HOBTRACK.TICKETTYPES            types
     , HOBTRACK.SECURITY_LEVEL         Security   
 WHERE Tick.ID IN (25031,25100,18123)

这是查询的执行和返回方式:

Statement stmt = con.createStatement(); // where con is the connection
rs = stmt.executeQuery(above_query); 

return rs;

最后,将返回的结果集 rs3 传递给一个方法,该方法while (rs.next())用于循环遍历该结果集并执行操作。这就是程序卡住的地方。关于可能是什么问题或如何识别问题的任何想法?

谢谢你的帮助 :)

4

0 回答 0