Redigera

Dela via


setMaxRows Method (SQLServerStatement)

Download JDBC driver

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

Syntax

  
public final void setMaxRows(int max)  

Parameters

max

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

Exceptions

SQLServerException

Remarks

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 JDBC Driver for SQL Server 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.

See Also

SQLServerStatement Members
SQLServerStatement Class