Showing posts with label paging. Show all posts
Showing posts with label paging. Show all posts

Monday, January 12, 2009

Paging database query

This is a very common scenario in web application where we have to show data in the DBMS in pages, since we cannot show indefinitely large quantity data in a browser in one go. I never tried it before and was wonder if it is easy to do that. To my surprise it is really easy to page the data in a web application. O/R mapping tools like hibernate makes the job even more easier.
Every RDBMS systems has a SQL syntax for limiting the amount of data chucked out.

With MySQL:
(any query you need to write) LIMIT {OFFSET}, {RECORD_PER_PAGE}


With Hibernate:
Query q = session.createQuery("...");
q.setFirstResult(start);
q.setMaxResults(length);
Pretty simple isn't it.. Please follow the below links for more reading..
Javalobby article on paging
Devx article on J2EE paging