当我打破while循环时,我必须将光标位置指回到前一个位置。
下面是我的while循环代码:
while (rs.next()) {
docId = rs.getString("DOCID");
System.out.println("In : extractData(1st):docId"+docId);
// if previous id is not match with the current id then exitfrom while loop.
if(previousDocId != null && !previousDocId.equals(docId)){
//move cruser back.
break;
}
thisIsAStringArray[0] = firstDocId;
String name1 = rs.getString("field_name");
System.out.println("field Name:"+name1);
if("address".equals(name1) && 1 == rs.getInt("field_type")){
thisIsAStringArray[1] = rs.getString("field_string");
}
//
previousDocId = docId;
}
请指教。
答案 0 :(得分:0)
获得ResultSet
后,您必须为其设置属性ResultSet.TYPE_SCROLL_INSENSITIVE
或ResultSet.TYPE_SCROLL_SENSITIVE
才能使其可滚动
假设您从ResultSet
获得了Statement
:
Statement statement = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE // scrollable
);
ResultSet rs = statement.executeQuery(your query);
并使用rs.previous()
向后移动。