我正在做一个简单的查询,我知道这个查询很好并且语法正确(执行它时没有异常,并返回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())
用于遍历此结果集并执行操作。这是程序卡住的地方。关于什么可能是问题或我如何识别它的任何想法?
感谢您的帮助:)