移动游标的方法

ResultSet提供了下面这些方法在可滚动的结果集中移动游标。

boolean next() throws SQLException

将游标往前移动,如果游标定位在记录上返回true,如果游标定位在after the last row上返回false。

boolean previous() throws SQLException

将游标往后移动,如果游标定位在记录上返回true,如果游标定位在before the first row上返回false。

void beforeFirst() throws SQLException

将游标定位在before the first row上,如果ResultSet中没有记录,不对结果集产生任何影响。

void afterLast() throws SQLException

将游标定位在after the last row上,如果结果集中没有记录,不对结果集产生任何影响。

boolean first() throws SQLException

将游标定位在first row上,如果结果集为空,就返回false。

boolean last() throws SQLException

将游标定位在last row上,如果结果集为空,就返回false。

boolean absolute(int row) throws SQLException

将游标移动到结果集中指定的row上。

如果row为正,则从结果集的开始往后计算,第一条记录为1,第二条为2。如果row大于结果集的记录数,游标就移到after the last row上。

如果row为负,则从结果集的最后往前算,最后一条为-1,倒数第二条为-2。如果row大于结果集的记录数,游标就移到before the first row上。

如果row为0,就将游标移到before the first row上。

boolean relative(int row) throws SQLException

将游标移动到相对于当前游标row间隔的游标上。

如果row为正,游标就向前移动,如果游标移动超出了最后一条记录,就将游标移动到after the last row上。

如果row为负,游标就向后移动,如果游标移动超出了第一条记录,就将游标移动到before the first row上。

如果row为0,游标就不做任何移动。

如果row为1,就相当于next()操作。

如果row为-1,就相当于previous()操作。

不能对forward-only ResultSet进行除next()以外的操作,若是使用了其他的定位操作,神通数据库 JDBC驱动将抛出SQLException异常。