Java 不使用next()方法从ResultSet获取值

Java 不使用next()方法从ResultSet获取值,java,jdbc,resultset,Java,Jdbc,Resultset,在调用next()方法之前,有没有一种方法可以从ResultSet中获取第一行? 代码类似于: String idElementPrev = /*here I would get the element*/ while (rs.hasNext()) { String idElement = rs.getInt("elementId"); if (idElementPrev == idElement) { //do something } } 条件有问题,

在调用next()方法之前,有没有一种方法可以从ResultSet中获取第一行? 代码类似于:

String idElementPrev = /*here I would get the element*/
while (rs.hasNext()) {
    String idElement = rs.getInt("elementId");
    if (idElementPrev == idElement) {
        //do something
    }
}

条件有问题,要解决问题,可以使用列表,也可以使用“包含”检查列表中是否存在该值,下面是一个示例:

List<int> list = ...;
int idElement;
while (rs.next) {
    idElement = rs.getInt("elementId");
    if (list.contains(idElement)) {
       //do this
    }else{
       //do this
    }
}
List=。。。;
智力因素;
while(rs.next){
idElement=rs.getInt(“elementId”);
if(list.contains(ideElement)){
//这样做
}否则{
//这样做
}
}

您想要什么?要比较第一行和第二行吗?因此,只需读取while循环外的第一行(您需要向前移动光标),然后执行循环,因为我有多个相同的值,并且我需要创建一个新对象,前提是ideelement是change,我之前不知道元素。我想我应该使用next()获取第一个元素,使用previous()回放光标。然后我可以循环到rs.next()@FedericoRampazzo,只需使用一个列表,并在第一次迭代中存储该列表中的第一个元素,在第二次迭代中,您可以使用contains和one进行检查