Reputation:
In a database consider that I have a table with 4000 rows. I am using JTable to list them in front end. During page load, I need to display only First - 20 rows. I have NEXT and PREVIOUS button in top, so that if I click NEXT button, next 20 rows must be fetched from database and loaded in table.
In short, on button click, I need to fetch a set of values (for example say 20 rows) dynamically from database. I am using Hibernate.
Can anyone suggest me a link or the procedure to do this. Any examples will be clear...
Thanks.
Upvotes: 0
Views: 262
Reputation: 27880
You could use ScrollableResults. Take into account that it might be unsupported by some DB drivers.
Or you could use setFirstResult
and maxResults
, for example:
Criteria criteria=session.createCriteria(Item.class);
criteria.addOrder(Order.asc("name"));
criteria.setFirstResult(100);
criteria.setMaxResults(50);
List pageResults=criteria.list();
You may also find the answers to this question useful: Using Hibernate's ScrollableResults to slowly read 90 million records
Upvotes: 1