在下面的代码片段中,我执行一个查询并将结果集传递给set
. 然后将set
分配给set1
。之后有一个 while 循环,一直持续到set.next
返回false
。是否如果set.next
在循环后返回 false ,set1
也会返回 false ?
ResultSet set = statement.executeQuery();
ResultSet set1 = set;
while (set.next()) {
if (set.getString(1).equalsIgnoreCase(keyword)) {
// If the search matches the exact keyword
list.put(set.getString(2), set.getString(1));
// Where key is the name of the node and value is, name of the file
}
}
我问这个是因为:
while (set1.next()) {
System.out.println("@@@Inside the while statement@@@");
if (set1.getString(1).contains(keyword)
&& set1.getString(1).compareToIgnoreCase(keyword) !=0) {
// If the search contains the keyword but does not exactly match
list.put(set.getString(2), set.getString(1));
// Where key is the name of the node and value is, name of the file
System.out.println("@@@Inside the if statement of second while loop !@@@");
}
}
这种while
构造永远不会起作用。是这个原因吗?如果是这样,我该怎么办?