Solved

how to show limited number of rows in a page

Posted on 2004-04-20
8
373 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
Comment Utility
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
Comment Utility
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
Comment Utility
Have a look at this:

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

it may be what you want...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 32

Expert Comment

by:ldbkutty
Comment Utility
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
Comment Utility
instead of :
iPage = Integer.parseInt(getParam( request, "FormNews_Page"));

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

Author Comment

by:mvkraju
Comment Utility
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
Comment Utility
PAQed, with points refunded (30)

Computer101
E-E Admin
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now