void topNRows( Connection db ) {
    String someQuery = "SELECT X, Y, Z FROM SOMETABLE ORDER BY X";
    int N= 100;
    Statement firstN= db.prepareStatement( someQuery );
    ResultSet rs= firstN.executeQuery();
    for( int i= 0; i != N && rs.next(); ++i ) {
        // process the row
    }
    // assert (N rows processed) or (no more rows)
    rs.close();
    firstN.close();
}

Example 3: Java partial fetch.

Back to Article