JDBC: LIMIT vs setmaxrows (Resultset)

I want to select the top 10 entries, I can use one of them:

  • Using setmaxrows in Resultset
  • Using LIMIT and OFFSET in sql statement

My question is: what are the advantages and disadvantages between them?

+2
source share
4 answers

In most cases, you want to use the offer LIMIT, but at the end of the day both will achieve what you want. This answer focuses on JDBC and PostgreSQL, but applies to other languages ​​and databases that use a similar model.

JDBC documentation for Statement.setMaxRowssays

If the limit is exceeded, extra lines are silently discarded.

. , . PostgreSQL JDBC , . maxRows AbstractJdbc2ResultSet. maxRows QueryExecutorImpl.

, PostgreSQL LIMIT :

LIMIT

, , , .

+4

setmaxrows , , Postgres, Oracle, Mysql .. Oracle rownum, postgres - limit, msqsql - top

.

+2

setFetchSize. JDBC , , ResultSet, , .

setMaxRows , ResultSet, Statement, .

, 2 JDBC API, setFetchSize , 100K . , ArrayList Jasper.

+2

, , , , , , , "TOP 1" numrows = 1. , " ", "". . , "" , . . , JDBC y/n. , , , , ... db , , "Speedwise " ... . , , , , ... "TOP 1"...

+1
source

Source: https://habr.com/ru/post/1605957/


All Articles