Forum Stats

  • 3,814,142 Users
  • 2,258,826 Discussions
  • 7,892,587 Comments

Discussions

setMaxRows vs Limit/rownum/top

1036962
1036962 Member Posts: 11

The JDBC API doc for setmaxRows says that "If this limit is exceeded, the excess rows are "silently dropped".

Consider a Query fetching 1000 rows and i configured setMaxRows to 10 (i.e.) PreparedStatement.setMaxRows(10) .

Now the data from the database , present in packets travelling to my machine contains 10 rows or 1000 rows ?

Tagged:

Answers

  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy

    JDBC is only an API, it doesn't "do" anything other than dictate the contract of its implementations. It depends on how the driver is built and thus on the people maintaining that driver how this particular demand is settled. Lets assume they're built to be efficient and so will not transfer unnecessary data over the line.

  • The JDBC API doc for setmaxRows says that "If this limit is exceeded, the excess rows are "silently dropped".
    Consider a Query fetching 1000 rows and i configured setMaxRows to 10 (i.e.) PreparedStatement.setMaxRows(10) .
    Now the data from the database , present in packets travelling to my machine contains 10 rows or 1000 rows ?
    

    First - forget about 'packets' travelling to the machine. Packets are physical and the size and content is determined mostly by your machine settings. The actual number of rows in a packet would also depend on the size of each row.

    The 'setMaxRows' value is used to stop fetching MORE results from the server. So AFTER fetching rows the setting will be checked and, if met, will prevent future fetches of data.

    Depending on the fetch size set/used by your code you might have fetched ALL 1000 rows to the client with the first fetch.

    What PROBLEM are you trying to solve?

    If you want to control the number of rows fetched to the client you also need to set the fetch size. Even then that will NOT control what the server does.

This discussion has been closed.