Moving ResultSet to first

// Create a scrollable result set
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");

// Move cursor forward
while (resultSet.next()) {
  // Get data at cursor
  String s = resultSet.getString(1);
}

// Move cursor backward
while (resultSet.previous()) {
  // Get data at cursor
  String s = resultSet.getString(1);
}

// Move cursor before first record
resultSet.beforeFirst();  //required statement in this case

 ResultSet能夠往回退,必須在PreparedStatment裏面配置 ResulSet相關屬性。ui

相關文章
相關標籤/搜索