Java JDBC将光标指向上一个结果集

Java JDBC将光标指向上一个结果集,java,jdbc,Java,Jdbc,当我中断while循环时,我必须将光标位置指向上一个位置 下面是my 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(

当我中断while循环时,我必须将光标位置指向上一个位置

下面是my 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;
}

请给我一些建议

当您获得
结果集时
必须设置属性
结果集。键入\u SCROLL\u SENSITIVE
结果集。键入\u SCROLL\u SENSITIVE
使其可滚动

假设您从
语句
中获得了
结果集

Statement statement = conn.createStatement(
   ResultSet.TYPE_SCROLL_INSENSITIVE // scrollable    
);
ResultSet rs = statement.executeQuery(your query);

然后使用
rs.previous()
向后移动。

在春天,我怎么能提到这一点?你是什么意思?您使用JDBC显示代码并要求spring解决方案?我使用spring批处理数据库,如下所示:如果您使用您在问题中提到的
ResultSet
,请按照我的回答进行处理。如果您想要spring的解决方案,请发布另一个问题,并附上您现在正在处理的详细代码