0

I'm using Java JDBC connecting to a database to execute the query.

The query executes and it fetches million rows from the database. If I store this million rows in my array it causes memory issues. How can I limit the number of rows being fetched.

Jason C
  • 38,729
  • 14
  • 126
  • 182
user1050619
  • 19,822
  • 85
  • 237
  • 413
  • We can't help you if we don't have your code. What you can do is limit your array. – JordyV Mar 18 '14 at 23:21
  • One option is that you can limit the number of rows fetched. `SELECT * FROM tablemane LIMIT 0, 5` will fetch first 5 rows. Then you can process as desired. – rgamber Mar 18 '14 at 23:31
  • Look at this question: http://stackoverflow.com/questions/3682614/jdbc-how-to-read-all-rows-from-huge-table in particular setFetchSize. – Glenn Mar 18 '14 at 23:40

1 Answers1

0

IF it is SQL - which it doesn't say, but I'm going to assume (reflex, I saw *dbc) - then there'll be a limit clause, EVEN Microsoft SQL (which is a laughable thing indeed) has a LIMIT clause.

For example (WHATEVER) LIMIT 5 means only 5 rows will be output (or updated, or deleted, as limits may be used there).

(WHATEVER) LIMIT 5,10 means 10 rows from the 5th row, so 6 to 15 if your rows start at 1.

Alec Teal
  • 5,770
  • 3
  • 23
  • 50