Search code examples
javajspjdbcresultset

Print the ResultSet values upto a certain number in JSP


this question is a bit weird, but I am after it for last couple of days.

I have sent ResultSet object to JSP page to display the records. It is displaying all the records of resultset in JSP using while(rs.next()){}.

My question is : Is there any method that will print the records of resultset from a certain number_of_row to a certain number_of_row?, e.g. I want to print the records between row-number 3 to 6.

I dont want Java Classes to take the loads like SQL : SELECT * FROM......LIMIT 3,3;

I want JSP to take step to do that e.g. while(rs.next(from 3 to 6)){} Any help ? Thanx in advance.


Solution

  • ResultSet has method, absolute() which takes the row no.

    So you could simply use:

    rs.absolute(3);
    while(rs.next()) {
        if(6 < rs.getRow()) {//get current row no
            break;
        }
        //get data
    }