title: How does a JDBC driver implement the setMaxRows method
body: <p>According to the JDBC specifications, the <a href="http://docs.oracle.com/javase/8/docs/api/java/sql/Statement.html#setMaxRows-int-" rel="nofollow"><code>Statement.setMaxRows(int maxRows)</code></a> method is supposed to:</p>
  
  <blockquote>
    <p>Sets the limit for the maximum number of rows that any ResultSet
    object generated by this Statement object can contain to the given
    number. If the limit is exceeded, the excess rows are silently
    dropped.</p>
  </blockquote>
  
  <p>When testing it against limiting the result set at the SQL level (ROWSET, TOP and LIMIT), both the JDBC and the SQL construct seem to perform very well.</p>
  
  <p>Even when selecting millions of rows, the <code>setMaxRows</code> doesn't seem to perform worse. </p>
  
  <p>Could it be because the database Executor might use a database cursor which only fetches records on demand, so when the driver reaches the <code>maxRows</code> threshold, the database can be instructed to close the cursor?</p>
  
  <p>This way, the database doesn't have to select a huge result set and send it to the wire, only to be discarded on the client-side.</p>