This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
    Bookmark Topic Watch Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger
  • Mark post as helpful
  • send pies
  • Report post to moderator
Pagination

How do I limit the number of rows displayed in the results page?

Often a database query will yield hundreds or thousands of rows of data.
Trying to display all of them in one webpage could be very slow and resource intensive. Worse, it results in a poor user experience for the person who actually has to scroll through all of this data.

Well-designed websites will return a small subset of the data and provide links to move to the next or last set.

The easiest way to accomplish this is by constraining the number of rows returned from the database query in the first place.


  • MySQL uses the 'LIMIT' keyword for this.
  • PostgreSQL uses the 'LIMIT' and 'OFFSET' keywords for this.
  • Oracle uses the 'ROWNUM' keyword. It doesn't work like LIMIT and OFFSET. You will probably find it strange (this page might help).
  • DB2 uses the 'ROWNUMBER' 'OVER' combination.
  • SQL Server uses the 'TOP' keyword, followed by the number of rows from the top of the result.


  • A typical query in MySQL would look something like:



    This will yield rows 11 through 60.

    (Ref : http://dev.mysql.com/doc/refman/5.0/en/select.html)


    Another way to limit the number of records returned is to use the


    Because this is part of the JDBC API, it works for all servers.

    It should be noted that with both approaches it is undefined which rows are returned. If you want particular rows returned, you should add an "order ..." clause so that the order of rows is defined.


    Javaranch has a forum dedicated to JDBC/SQL issues where you can go to read more about formulating SQL statements: JDBC forum

    JavaRanch Journal article on paging with JDBC and JSP


    Here are some notes from other conversations on pagination:



    Back to the JspFaq or the JdbcUsageQuestions
     
    Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
      Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!