Skip Headers

# Specifying the Maximum Rows Returned

Previous

Next

You can limit a query to a specified maximum number of rows. Use this feature to avoid queries that can return an excessive number of objects.

To specify a maximum number of rows, use the `setMaxRows` method, and pass an integer that represents the maximum number of rows for the query, as shown in Example: Setting the Maximum Returned Object Size.

Setting the Maximum Returned Object Size

    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.setMaxRows(5);
    Vector employees = (Vector) session.executeQuery(query);

The `setMaxRows` method limits the number of rows the query returns, but does not let you acquire more records after the initial result set.

If you want to browse the result set in fixed increments, use either cursors or cursored streams. For more information, see "Handling Cursor and Stream Query Results" .