?
Solved

how to show limited number of rows in a page

Posted on 2004-04-20
8
Medium Priority
?
381 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 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