Skip to content

Instantly share code, notes, and snippets.

@aidoskz
Created November 13, 2014 03:31
Show Gist options
  • Select an option

  • Save aidoskz/fad4676e118f2e1b884c to your computer and use it in GitHub Desktop.

Select an option

Save aidoskz/fad4676e118f2e1b884c to your computer and use it in GitHub Desktop.
Pagination of list table from Oracle SQL
public List<T> getList(long first, long last, String selectSql) throws SQLException {
List<T> list = new ArrayList<T>();
String query = "select * from (select rownum rn,sq1.* from " +
"("+selectSql+") sq1)" +
" sq2 where sq2.rn>=" + first + " and sq2.rn<=" + last;
Statement stmt = this.conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
list.add(convert(conn, rs));
rs.close();
stmt.close();
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment