Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to show limited number of rows in a page

Posted on 2004-04-20
8
Medium Priority
?
382 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

972 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