Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 520449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:08:47+00:00 2026-05-13T08:08:47+00:00

How do I convert Resultset object to a paginated view on a JSP? For

  • 0

How do I convert Resultset object to a paginated view on a JSP?

For example, this is my query and result set:

pst = con.prepareStatement("select userName, job, place from contact");
rs = pst.executeQuery();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:08:48+00:00Added an answer on May 13, 2026 at 8:08 am

    To start, you need to add one or two extra request parameters to the JSP: firstrow and (optionally) rowcount. The rowcount can also be left away and definied entirely in the server side.

    Then add a bunch of paging buttons to the JSP: the next button should instruct the Servlet to increment the value of firstrow with the value of rowcount. The previous button should obviously decrement the value of firstrow with the value of rowcount. Don’t forget to handle negative values and overflows correctly! You can do it with help of SELECT count(id).

    Then fire a specific SQL query to retrieve a sublist of the results. The exact SQL syntax however depends on the DB used. In MySQL and PostgreSQL it is easy with LIMIT and OFFSET clauses:

    private static final String SQL_SUBLIST = "SELECT id, username, job, place FROM"
        + " contact ORDER BY id LIMIT %d OFFSET %d";
    
    public List<Contact> list(int firstrow, int rowcount) {
        String sql = String.format(SQL_SUBLIST, firstrow, rowcount);
    
        // Implement JDBC.
        return contacts;
    }
    

    In Oracle you need a subquery with rownum clause which should look like:

    private static final String SQL_SUBLIST = "SELECT id, username, job, place FROM"
        + " (SELECT id, username, job, place FROM contact ORDER BY id)"
        + " WHERE ROWNUM BETWEEN %d AND %d";
    
    public List<Contact> list(int firstrow, int rowcount) {
        String sql = String.format(SQL_SUBLIST, firstrow, firstrow + rowcount);
    
        // Implement JDBC.
        return contacts;
    }
    

    In DB2 you need the OLAP function row_number() for this:

    private static final String SQL_SUBLIST = "SELECT id, username, job, place FROM"
        + " (SELECT row_number() OVER (ORDER BY id) AS row, id, username, job, place"
        + " FROM contact) AS temp WHERE row BETWEEN %d AND %d";
    
    public List<Contact> list(int firstrow, int rowcount) {
        String sql = String.format(SQL_SUBLIST, firstrow, firstrow + rowcount);
    
        // Implement JDBC.
        return contacts;
    }
    

    I don’t do MSSQL, but it’s syntactically similar to DB2. Also see this topic.

    Finally just present the sublist in the JSP page the usual way with JSTL c:forEach.

    <table>
        <c:forEach items="${contacts}" var="contact">
            <tr>
                <td>${contact.username}</td>
                <td>${contact.job}</td>
                <td>${contact.place}</td>
            </tr>
        </c:forEach>
    </table>
    <form action="yourservlet" method="post">
        <input type="hidden" name="firstrow" value="${firstrow}">
        <input type="hidden" name="rowcount" value="${rowcount}">
        <input type="submit" name="page" value="next">
        <input type="submit" name="page" value="previous">
    </form>
    

    Note that some may suggest that you need to SELECT the entire table and save the List<Contact> in the session scope and make use of List#subList() to paginate. But this is far from memory-efficient with thousands rows and multiple concurrent users.

    For ones who are interested in similar answer in JSF/MySQL context using h:dataTable component, you may find this article useful. It also contains some useful language-agnostic maths to get the “Google-like” pagination nicely to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 248k
  • Answers 248k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use example from here http://pinvoke.net/default.aspx/user32.EnumDesktopWindows then just check window state May 13, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer The Designer property is a so-called navigation property, and those… May 13, 2026 at 8:53 am
  • Editorial Team
    Editorial Team added an answer Update: Netbeans has dropped support for ruby, unfortunately. The netbeans… May 13, 2026 at 8:53 am

Related Questions

AIM : Convert a resultset to XML and assign the result to a variable
Say, You have an application which lists down users in your application. Ideally, if
How do you specify the Func signature for anonymous objects? new Func<DataSet, **IEnumerable<int>>** I
Hi I am trying to update a div with some html from another div.
I have some JSON returned to the browser like this product: { Title: School

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.