setMaxRows Method (SQLServerStatement)

Sets the limit for the maximum number of rows that any SQLServerResultSet object can contain to the given number.

public final void setMaxRows(int max)



An int that indicates the maximum number of rows, or 0 if there is no limit.

This setMaxRows method is specified by the setMaxRows method in the java.sql.Statement interface.

This setMaxRows method has no effect for dynamic scrollable cursors. The application should use SELECT TOP N SQL syntax to limit the number of rows returned from potentially large result sets.

When the setMaxRows method is called, the Microsoft SQL Server 2005 JDBC Driver executes the SET ROWCOUNT SQL statement when it runs the application's query. This causes the JDBC driver to limit the maximum number of rows affected by all the Transact-SQL statements executed by that query, not just the number of rows returned by that query. If the application needs to set a limit only on the top-level SQLServerResultSet object, it should use SELECT TOP N SQL syntax in the query instead of the setMaxRows method.

For more information about the SET ROWCOUNT SQL statement, see the "SET ROWCOUNT (Transact-SQL)" topic in SQL Server Books Online.