-3

My java web application is retrieving a large dataset from the DB (DB2) and displaying the records on a webpage. Since the number of records is very large , the page takes a little time to load (about 15 secs) To improve this , I want to implement pagination on the server side , ie fetch only 50 records at a time and show it on the page. Then when the user clicks on Next , the next 50 records are fetched and displayed.

I have already implemented this on the client side ie I am showing the data in chunks of 50 , but I am still fetching the entire data in one database call, due to which the page takes time to load.

How can I implement the pagination on the server side ie fetch only 50 records at a time ?

Thanks in advance.

Parag M
  • 93
  • 4
  • 9
  • JDBC also has the concept of fetch size - Statement.setFetchsize and the fetchSize property of the driver. – Rob Wilson Mar 27 '18 at 14:10
  • @RobWilson JDBC fetch size is not what the OP wants. JDBC fetch size is a hint to the driver to fetch rows in batches of _(fetch size)_ rows, but it will still retrieve all rows. – Mark Rotteveel Mar 27 '18 at 15:25

1 Answers1

1

Use LIMIT and OFFSET. In your client code, keep track of the current offset that you want. In this case LIMIT would be 50 and OFFSET would be some multiple of 50.

Select * From MY_TABLE ORDER BY XYZ LIMIT 50 OFFSET 0

xtratic
  • 4,600
  • 2
  • 14
  • 32