Solved

how to show limited number of rows in a page

Posted on 2004-04-20
8
376 Views
Last Modified: 2010-04-01
Hi,

    I have a situation where I have chances to get tons of data with my ResultSet for my query.
I wanted to show100 records per page. I wanted to have next and previous links in my page.
If it is the starting page I should not have previous link. If it is my last page I should not have next link.

How to implement this? I never did this before. I appreciate if could give me ideas.

Thanks
0
Comment
Question by:mvkraju
8 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10872126
you have to get the total number of records and then divide that by 100.. that will give you the number of pages you will have..
when you call your next page you must pass the current page number and then multiply that number by 100 and loop your recordset starting that that number until you reach 100

you get the idea,
Ghost
0
 

Author Comment

by:mvkraju
ID: 10872334
It guess it's an exprensive idea, bcz we are Unnecessarily retrieving all the data, no matter wheter user is going to see all the data.
  Say for example my query returned a resultset with 100,000 records, if user see only first 2 pages, in this scenario it's waste of retrieval of 100, 000 records.
 
 
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10875953
Have a look at this:

http://jsptags.com/tags/navigation/pager/index.jsp

it may be what you want...
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 32

Expert Comment

by:ldbkutty
ID: 10917754
I have a similar application....Try to unedrstand my appliation that displays 100 Records and uses scroller ...for next/previous page.


    int iCounter=0;
    int iPage = 0;
    boolean bIsScroll = true;
    String sSQL="";
    String sPage = "";
    int RecordsPerPage = 100;
  // Build full SQL statement
 
  sSQL = "select n.field1 as n_field from tablename n;
 
  String sNoRecords = "     <tr>\n      <td > NO RECORDS </font></td>\n     </tr>";
  out.println("    <table> ");
     
  try {
    // Select current page
    iPage = Integer.parseInt(getParam( request, "FormNews_Page"));
  }
  catch (NumberFormatException e ) {
    iPage = 0;
  }

  if (iPage == 0) { iPage = 1; }
  RecordsPerPage = 20;
  try {
    java.sql.ResultSet rs = null;
    // Open recordset
    rs = openrs( stat, sSQL);
    iCounter = 0;
    absolute (rs, (iPage-1)*RecordsPerPage+1);
    java.util.Hashtable rsHash = new java.util.Hashtable();
    String[] aFields = getFieldsName( rs );

    // Show main table based on recordset
    while ( (iCounter < RecordsPerPage) && rs.next() ) {

      getRecordToHash( rs, rsHash, aFields );
      String fldfield1 = (String) rsHash.get("n_field1");
 
      out.println("     <tr>");
      // Display the fields here
      out.print("</tr>");
   
      iCounter++;
    }
    if (iCounter == 0) {
      // Recordset is empty
      out.println(sNoRecords);
      bIsScroll = false;
    }

    else {
    // Parse scroller
    boolean bInsert = false;
    boolean bNext = rs.next();
    if ( !bNext && iPage == 1 ) {
   
      out.print("     <tr>\n      <td>\n  ");
      out.println("\n      </td>\n     </tr>");
   
    }
    else {
      out.print("     <tr>\n      <td>");
      bInsert = true;
   
      if ( iPage == 1 ) {
        out.print("\n       <a href_=\"#\"><font style=\"font-size: 10pt; color: #000000; font-weight: bold\">Previous</font></a>");
      }
      else {
        out.print("\n       <a href=\""+sFileName+"?FormNews_Page="+(iPage - 1)+"#Form\"> Previous </a>");
      }
 
      out.print("\n       [ "+iPage+" ]");
 
      if (!bNext) {
        out.print("\n       <a href_=\"#\"> Next </a><br>");
      }
      else {
        out.print("\n       <a href=\""+sFileName+"?"+"FormNews_Page="+(iPage + 1)+"#Form\"><font style=\"font-size: 10pt; color: #000000; font-weight: bold\">Next</font></a><br>");
      }
   
      if ( ! bInsert ) {
        out.print("     <tr>\n      <td colspan=\"2\" style=\"background-color: #FFFFFF; border-style: inset; border-width: 1\"><font style=\"font-size: 10pt; color: #000000; font-weight: bold\">");
       }
   
      out.println("</td>\n     </tr>");
    }
 
    }

    if ( rs != null ) rs.close();
    out.println("    </table>");
   
  }
  catch (Exception e) { out.println(e.toString()); }

AND ---->


   /**
  * Absolute function
  */
  public static void absolute(java.sql.ResultSet rs, int row) throws java.sql.SQLException{
    for(int x=1;x<row;x++) rs.next();
  }
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 10918586
instead of :
iPage = Integer.parseInt(getParam( request, "FormNews_Page"));

use this:
iPage = Integer.parseInt(request.getParameter("FormNews_Page"));
0
 

Author Comment

by:mvkraju
ID: 10949700
TimYates link was good, but i don't want to implement that tough one. In that link he did not gove proper documentions to make use of those custome tags.
The following link is more helpful for me to understand the concept
http://www-106.ibm.com/developerworks/db2/library/techarticle/0307balani/0307balani.html
then i implement my own logic in order to show 60 records per page.

Thanks for ur support.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 11166613
PAQed, with points refunded (30)

Computer101
E-E Admin
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
project group option in netbeans equivalent term in eclipse 1 50
best way to search/remove a file from an EAR file 3 109
login form jsp example 2 26
going to wrong jsp page 2 22
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
Adding Computers to AD groups through an SCCM Task Sequence
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question