Re: paging large results

Discussion in 'Java' started by swat42, Jul 14, 2003.

  1. swat42

    swat42 Guest

    I don't use Struts so there might be an answer there that i am not aware of.
    What could be done is make a query to the database when the user ask for the
    page and store it into his session:
    Connection con = ...
    Statement st = con.createStatement(...)
    ResultSet rs = st.executeQuery(...)
    rs.setFetchSize(20); // depends on the drivers
    request.getSession().setAttribute("mypage.rs", rs);

    And then retrieve the infos needed when the user ask for a page:
    ResultSet rs = (ResultSet)request.getSession().getAttribute("mypage.rs");
    int page = request.getParameter("page");
    rs.absolute(page*20);
    rs.previous();
    for(int i=0; i<20 && rs.next(); i++) {
    // Get one line of results and print it to the jsp
    }

    About the not to go to the database, you may perform your own filtering
    using the already existing ResulSet object, but in some cases, it might be
    faster to requery the databse with some more specific details. It depends on
    such factors as the database cache and indexes it uses to get the data.
    Don't forget pass the proper parameters to con.createStatement()
    (resultSetType and resultSetConcurrency) to make sure that your datas are
    safe and react as you want.

    "srini" <> wrote in message
    news:...
    > Hi,
    > I am using struts freamework to develop a project. I have need to
    > dispaly large results on the jsp page with search capability, I have
    > to show only 20 results per page and need to have next and previous
    > buttons to navigate the results that I retrived from database. I also
    > need to provide the user a text box where he can enter a value (say a
    > telephone number), and I sould be able to show the user only the
    > record containing that field value. Is there any pattern in struts
    > frame work which can provide me this and what is the best way to
    > handle this situation. I need not goto the databse to get new results
    > each time b'cos my database does not change.
    >
    > Thanks
    > vulli
     
    swat42, Jul 14, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    DataSet paging vs Datareader paging

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    10,863
    Scott Allen
    Oct 8, 2004
  2. wh1974
    Replies:
    0
    Views:
    2,482
    wh1974
    Jan 12, 2005
  3. Red
    Replies:
    1
    Views:
    766
  4. SAL

    Paging data results??

    SAL, Nov 29, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    696
    sloan
    Nov 29, 2007
  5. Rabii
    Replies:
    0
    Views:
    131
    Rabii
    Sep 12, 2004
Loading...

Share This Page