SQL LIMIT vs. JDBC Statement setMaxRows. Which one is better?

后端 未结 5 1766
离开以前
离开以前 2021-02-08 20:13

I want to select the Top 10 records for a given query. So, I can use one of the following options:

  • Using the JDBC Statement.setMaxRows() method
  • Using LIMI
5条回答
  •  天命终不由人
    2021-02-08 20:34

    setFetchSize Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects generated by this Statement.

    setMaxRows Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement object can contain to the given number.

    I guess using above 2 JDBC API you can try by using setFetchSize you can try if it works for 100K records. Else you can fetch in batch and form ArrayList and return it to your Jasper report.

提交回复
热议问题