A twist on only getting 20 records at a time

Hi,
Goal:
Generate a search-engine like result page which displays 20 records at a time. Clicking "Next" will permit viewing the next 20 records, and so on.
Current code:
A JSP page posts a form to a servlet which, based on form selections, dynamically builds a SQL statement, which in turn is passed to a Bean which queries the DB and returns ALL records. Works great, but returns too much data for a web page (JSP).
Problem:
I have posted on the JSP forum, and have only been pointed to sites offering Custom JSP Tags which either query all records at once and only show you X at a time, (which I consider inefficient) or place the JDBC/SQL code in the JSP page, which I don't like either. So....
Question:
How do I achieve this? I have tried playing with the getMaxRoxs() and setFetchSize() methods to no avail. I am relatively new to this, but I think it has a lot to do with how JSP pages instantiate Beans (I.E: Every time the page loads, the bean is instantiated and all records are returned).
Any help is greatly appreciated! I have tried so many things and searched the web, but have not found any concrete examples with code.
- J

My proposal was smth like this:
ArrayList myData = new ArrayList();
while (rSet.next()) {
    MyObjType myObj = new MyObjType(...);
    int i = 0;
    myObj.setAttribute1(rSet.getXXX(++i)); // getXXX is the proper method for the type of myObj.attribute1
    myObj.setAttribute2(rSet.getXXX(++i)); // getXXX is the proper method for the type of myObj.attribute2
    myObj.setAttributen(rSet.getXXX(++i)); // getXXX is the proper method for the type of myObj.attributen
    myData.add(myObj);
session.setAttribute("myData", myData);
...Here MyObjType is the type (class) designed by you to hold one record of your result set. Example:
For the
TABLE BOOK
ID NUMBER(10)
TITLE CHAR(30)
PRICE DECIMAL(2, 12)
AUTHOR_ID NUMBER(10)
Your MyObjType class will be probably named Book and will look like this:
public class Book {
    private long id = -1;
    private String title = null;
    private double price = Double.NaN;
    private long authorId = -1;
    public long getId() {
        return this.id;
    public void setId(long id) {
        this.id = id;
    public long getAuthorId() {
        return this.authorId;
    public void setAuthorId(long authorId) {
        this.authorId = authorId;
    public String getTitle() {
        return this.title;
    public void setTitle(String title) {
        this.title = title;
    public double getPrice() {
        return this.price;
    public void setId(double price) {
        this.price = price;
}So, you have an ArrayList of Book objects stored in your session object. Now you receive a request like this:
gimmemydata?rowsfrom=20&rowsto=40
Your JSP does just:
<%
ArrayList myData = (ArrayList) session.getAttribute("myData");
int rowsFrom = -1;
int rowsTo = -1;
try {
    rowsFrom = Integer.parseInt(request.getParameter("rowsfrom"));
    rowsTo = Integer.parseInt(request.getParameter("rowsto"));
catch (Exception ex) {;}
if (rowsFrom < 0 || rowsTo < 0) {
    rowsFrom = 0;
    rowsTo = 20;
%>
<table>
<%
for (int i = rowsFrom; i < rowsTo; i++) {
    Book book = (Book) myData.get(i);
%>
<tr>
  <td><%= book.getTitle() %></td>
  <td align="right"><%= book.getPrice %></td>
</tr>
<%
%>
</table>
...It is as easy as that...
Sorry, the closing brackets of the tags look a bit funny :-)

Similar Messages

  • Getting only a few records at a time.

    Using a Select * from. Is there an option where I get only so many records. This is for a console application. I wanted some thing where it will display only 3 records at a time. And then I have the option of viewing the next 3 and then the next 3 records
    and so on.
    Any one have any ideas.
    Merry Christmas EVERY ONE and thanks to all the members on msdn forums for helping me with my code.
    Joe Moody
    http://www.starfiresoft.com
    Pro-Forums
    Delta Force Barracks
    On the Frontlines

    Thanks. It doesn't matter as long as I can get it to work. The idea is to display 3 records at a time. Then the user should be able to go backward or forward in the list. Let me show you what I have. This will give you some idea on how I have it displaying
    the info.
    SqlCeCommand cm = new SqlCeCommand("SELECT * FROM users", cn);
    //cm.Parameters.AddWithValue("@tooid", num);
    //cm.Parameters.AddWithValue("@fromid", Id);
    SqlCeDataReader rd = cm.ExecuteReader();
    try
    while (rd.Read())
    Door.CursorRight(10);
    Door.WriteLn("|0C___________________________________________________");
    Door.CursorRight(10);
    Door.WriteLn("|0FId |04: |03" + rd["Id"].ToString() + " |0FName |04: |03" + rd["username"].ToString());
    Door.CursorRight(10);
    Door.WriteLn("|0FStatus |04: |03" + rd["status"] + " |0FDate Jointed |04: |03" + rd["joindate"]);
    Door.CursorRight(10);
    Door.WriteLn("|0C___________________________________________________");
    catch (Exception e)
    throw new Exception(e.Message);
    cn.Close();
    This is inside of a do loop. and at the bottom I have it waiting for user input. or the user can quit and return to the main menu.
    Door.WriteLn();
    Door.Write("|07Page |0F<|04||0F> |0FQ|09)|0BQuit |07Choice |04: |0C");
    cc = Char.ToUpper(Door.ReadKey());
    Above is my prompt. This waits for user input. and I use a switch to tell the software what to do. Any way if you want to know what Door.writeLn() is, Think of it like this "Console.Writeline()". This is just a library I use for the kind of programming I
    do.Any help would be great. Thanks and have a safe Xmas.
    Joe.
    http://www.df-barracks.com Delta Force Barracks
    http://www.starfiresoft.com Starfire Software

  • XML import only creates one record at a time

    Hi All,
    I have an XML import map that automatically imports data into main product table. It's working fine when the XML file has only one main record. When it has more than one record, the import manager and import server can only import the last record in the file and skip the rest.
    I already checked the record matching tab. It correctly shows that all records will be created and 0 will be skipped. Even the log file indicates all records are created after I execute the map. Yet, when I try to look for them in the data manager, I can only find the last one. If I execute the map with the exact same file again, it will create one more record again and skip the rest.
    Someone else posted the same question a while back: Import map issue one record at a time. But it was never answered. Does anyone else have this issue? Is this a MDM bug?
    Thanks,
    Kenny

    Hi Kenny,
    Please refer to the note below:
    Note 1575981
    Regards,
    Neethu Joy

  • I only get 52 minutes of play time from a CD that I downloaded from ITunes

    The CD has a 60 minute run time but I only get 52 minutes on the CD-R that I burned from the downloaded CD.

    Vincy28 wrote:
    I purchases some karaoke songs from itunes store,
    The tracks labeled "karaoke" in the iTunes Store are only instrumental backing tracks;  they are not actual karaoke tracks.  They do not have lyrics, and cannot be burned to the usual CD+G format that a karaoke machine will accept.
    If you want actual karaoke tracks,  go to a specialty online download store such as KaraokeDownloads.com. 

  • I noticed that any other code in my while loop only gets called at the 1st time through the loop and when a event is executed.

    HI there!
    I have a while loop, in which i am reading from/writing  to a compact rio. Furthermore, i added a event structure, its the 1st time i'm using it so i'm a bit lost at times.
    I have the event structure set up for all my button i want to trigger an event. However, i have some other code which i would also like to be executed, evebn though no event has been executed.
    I noticed that the other stuff in the loop only gets executed the 1st time through the loop and when an event is triggered.
    My question therefore is, how do i get the other stuff to execute as well?
    Please advise.
    Thanks.
    Regards,

    Put the other code in the timeout event case.  Wire some positive value to the timeout hourglass input.  That code will execute everytime a timeout occurs.  For instance, if you wire 100 into the timeout, the code in that case will execute every 100 mSec.
    - tbob
    Inventor of the WORM Global

  • In mail.app I only get 4 emails at a time

    Hello, since I updated to  OS X Lion, I'm having problems with the Mail.app. Bassically when I ask it yo get new mail, it onley get 4 email at a time. After that I have to press again the Get Mail button to get more mail.
    Does anyone have something like it? Have you solved it?
    Thanks

    Press the escape (esc) key to exit full-screen mode.

  • Recording a show after it starts.. you only get a recording from that spot...not the beginning

     (as it says on page 19 of User Guide)
    I fear I have made a major mistake switching from Direct TV... this feature worked flawlessly on their DVR (to which I had a 1TB external drive attached) .     I may eat the $400 termination fee and go back..  I think a week on FIOS is about all I can stan.

    Your 100% correct, Direct TV can only record the entire live program if you were already tuned to it, not if you just change to it. I never said that Direct TV could do that and Direct TV never says or implies that either.  Verizon on the other hand explains it this way...verbatim from page 19 of the Verizon FiOS user guide:
    "HERES HOW TO RECORD LIVE TV
    To record a show that's currently playing:
    o Press the REC button on the remote
    Got to the show late? No Problem: If you start recording after the show has started, the DVR will actually record the show from the beginning. So you'll have it all.
    To schedule recording of an upcoming program........"
    The limitation with Direct TV is obviously because it automatically is buffering channel feed, usually as long as the last couple of hours.... you can even go back and record the previous show if its in that window.  By a sat feed.
    Verizon has a fat fiber-optic cable pipe plugged into my house carrying internet, phone and tv with room to spare. Sadly,  I am not the genius you obviously are, Mr. Faraday,  so I'm not certain that Verizon doesn't do something like buffer this stuff on their end and then push it down the pipe to me if I want to see it from the beginning.   Would be an easy qualification in the manual don't ya think? You know ".....Got to the show late? No Problem, as long as you are have been tuned that channel....... "        
    Oh wait... this is the same company who matter-of-factly told me caller id would work on my tv, all I had to do was enable it.    Kewl.. I enabled it.   Nuthin.  Called support. Told me it takes 24-48 hours to kick-in.  No prob.  I can wait. Couple days later.. still nothing, called support back.  This time got someone who knew something and they informed me that you need Verizon's Call Assistant and Visual Mailbox for on-screen caller id to work.  Evidently only Verizon, well at least some in Verizon, know  this little tidbit.  (as I'm certain you do as well, von Goethe) Dummy Me, I didn't know that.  Gosh.. maybe a couple lines in a manual or on screen....you know for us nitwits.... would that kill them?  
    So you are correct, Mr. Wittgenstein, I am a **bleep**. I'm a Verizon customer aren't I?

  • CUBE Not getting All records from DSO

    Hi Experts ,
    We have a situation where we have to load data from a DSO to a Cube . The DSO contains only 9 records and while we r loading the data into cube , the cube is only getting 2 records . Thus 7 records are missing. Also The Cube contains more Fields  than DSO. in the transformations , for the extra fields we have written end routine and those extra fields will get data by reading master data .. Any pointers how to get the missing records or what is the error ...
    Sam

    Why multiple threads ????

  • I have an inetrnet modem and the time capsul one, I need to shutdown the internet modem signal so I only get the one from Time capsul. Does anyone knows how to do that?

    How do I turn off a modem signal so I only get the one from the time capsul?

    What is the make & model of your modem?

  • Fetching 10 records at a time

    Product.Category dimension has 4 child nodes Accessories,Bikes,Clothing n Components.My problem is when I have thousands of first level nodes my application takes a lot of time to load. Is there a way to fetch only say 100 records at a time? So then when
    i click a next button i get the next 100
    Eg:On the 1st click of a button I fetch 2 members
    WITH MEMBER [Measures].[ChildrenCount] AS
    [Product].[Category].CurrentMember.Children.Count
    SELECT [Measures].[ChildrenCount] ON 1
    ,TopCount([Product].[Category].Members, 2) on 0
    FROM [Adventure Works]
    This fetches only Accessories. Is there a way the fetch the next two records Bikes n Clothing on  click.
    Then Components on the next click. So on an so forth.

    Hi Tsunade,
    According to your description, there are thousands of members on your cube. It will take long time to retrieve all the member at a time, in order to improve the performance, you are looking for a function to fetch 10 records at a time, right? Based on my
    research, there is no such a functionally to work around this requirement currently.
    If you have any concern about this behavior, you can submit a feedback at
    http://connect.microsoft.com/SQLServer/Feedback and hope it is resolved in the next release of service pack or product. Your feedback enables Microsoft to make software and services the best that they can be, Microsoft might consider to add this feature
    in the following release after official confirmation.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Hello, this might be a basic question, but how do you open QuickTime to record a new webinar? I have a new MacBook Pro with Yosemite and can only get QuickTime to appear in Finder but not actually open to allow me to record something new. Thx.

    Hello, this might be a basic question, but how do you open QuickTime to record a new webinar? I have a new MacBook Pro with Yosemite and can only get QuickTime to appear in Finder but not actually open to allow me to record something new. Thx.

    Hi Winterwilly,
    Welcome to Apple Support Communities. 
    The article linked below answers your question of how to use QuickTime to record something on your MacBook Pro’s screen.
    QuickTime Player 10.x: Record your computer’s screen
    Cheers,
    -Jason

  • Recording stereo audio and only getting one side - what gives?

    Recording audio in stereo mode in logic and only getting one side showing on the meter and same side showing on the audio file - I've checked the interface - is there a logic setting I'm missing?

    Is Universal Track Mode enabled?

  • DTP Indicator Only Get Delta Once: How to handle deleted records in source

    Hi colleagues,
    I have checked some messages and blogs, but could not find any solution for deleted records in source system.
    My source system is not able to delivere delta for my table of interest. So I checked "Only Get Delta Once" in my DTP and made some tests.
    It works very well for changes of existing records of the source table.
    But, SAP help on this features wirtes:
    ...If this is not logically possible because, for example, data is deleted in the source without delivering reverse records, you can set this indicator and perform ...
    I checked this feature by selecting less data from source at the second load from the same table. But recordmode does not get an deletion flag for the now missing records. So, the indicator "Only Get Delta Once" does not work like BI standard delta mechanism?
    What is wrong?
    Thanks and regards,
    Wolfgang

    Hi,
    If you select the option 'Only get delta once', then every request in the PSA will only be loaded into the Data target once. For example. If you load a full request into the PSA through an InfoPackage and then load it to the Cube. In a snapshot scenario, when the new full load comes to the PSA you will need to delete the previous request from the cube before loading the new request.
    But if you delete the previous request from the cube, and not from the PSA - and if you haven't checked the 'Only get delta once' flag, when you execute the DTP, it will load both previous and the new requests from the PSA to the cube. In order to avoid this you have 2 options:
    1. You can delete a request from the PSA after every successful load into the Cube OR
    2. You can check the 'Only get delta once' flag in the DTP so that it won't load any request it has loaded into the cubes previously even if it was deleted from the cube.
    Using the second option de-couples the PSA maintenance from your regular data loading and also saves you an additional step of deleting the PSA request in your process chain.

  • Info Cube not getting full records

    Hi All,
    I am extracting data from the flat file (60k records..of which most fields have binary values),, am getting the values into data source..but when loading from data source to info cube am not getting total records..
    the load is successful and it is showing as transferred 60k records and added 510 records in the manage tab of the info cube.
    what would be the problem ....any help is appreciated.

    Hi,
    Data with same combination for characterstic is added and only for unique charactersitc value it will give new record.
    Material---Customer-Price
    10002----- C1--
    20
    10002----- C1--
    20
    10002----- C1--
    20
    10002----- C2--
    20
    SO As you can see in flat file 4 records are there but in inofcube it will be only 2
    Data with same combination of charactersitc is added and with unique combo only it will display.
    Hope it clears you.
    Also in addition please check the data in flat file.
    Regards,
    AL

  • Not getting all records in pagination

    I am also have a problem getting all records in the report as the post on Apr. 21,2004. My reports pagination stops at 500. When I set the 'max row count' to 100000. The pagination at the bottom of my page disapears. When I leave 'max row count' empty, it only goes from 1-500. No way to view records past the 500th record.
    I see there was a post on Apr. 21, 2004 about the same thing but it did not specify a fix or work around or if I'm missing a setting. (also tried the log off/on but did not help).
    *My pagination Scheme is 'Row Ranges 1-15 16-30 in select list(wiht pagination)'
    *My report has 1000+ records.
    Thanks, Paula

    The actual number of rows supported by the select list depends on how many rows you show on each page. If you go with the default of 15 rows, you would be able to use the select list with close to 5000 rows. If you increase the number of rows per page, the select list will work with even more rows.
    If the select list can't be used, it may make sense to consider using the "row ranges with set pagination" style. Set pagination lets you navigate from one set to the next instead of one page to the next, so you can navigate through your result set a lot quicker.
    However the best option for reports with that many rows would be "row ranges x-y", without showing the total number of rows. The reason is that the report renders a lot faster if you don't have the total number of rows calculated. In order to better be able to find certain records, I would recommend a search field on your report page that lets you filter the result set.
    Hope this helps,
    Marc

Maybe you are looking for

  • Can I download onto a usb flash drive instead of a IPod

    Can I download onto a usb flash drive instead of a ipod?

  • New Cinema Displays on an (old) G4-867???

    Hi. I have a PPCG4 867 MHz (OS 10.4.8, 512MB RAM) with factory installed NVIDIA GeForce2 MX with TwinView display card. I'd like to upgrade to a new cinema display, either a single 23" or dual 20" setup. I do not do heavy graphics or gaming, but just

  • Standard Proxy Deleted:Method To Restore

    Hi guys, From the transaction code SPROXY, I was supposed to regenerate the standard proxy so that the changes made on the PI end for the same interface reflect in ECC as well. But my mistake I deleted the standard proxy and when I try to create the

  • XML Forms Behaviour

    Hi all! I've finished a XML Forms Application which will be very similar to Announcements: a Date field and a Text field, simple as that. However, i am trying now to simulate with this application the behaviour that Collaboration Banner iView has: In

  • IMovie Lockup

    I am a new iMac user, previously a PC guy.  While using imovie it locke up and will not function.  While I can minimize the screen into the dock, it will not let me close the program or it will not let me shut down the computer.  Is there some kind o