aspose file tools*
The moose likes JSP and the fly likes how to use NEXT and Previous Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to use NEXT and Previous" Watch "how to use NEXT and Previous" New topic
Author

how to use NEXT and Previous

sumit malik
Greenhorn

Joined: Oct 31, 2001
Posts: 21
Friends my problem is if i am getting say 200 rows in a resultset from a database and i want list them in a set of say 20rows per jsp page.How can i do this.Also tell me how to get the rowcount from the resultset.
Dharmesh Chheda
Ranch Hand

Joined: May 08, 2001
Posts: 204
get all the records and place it in a vector and then display 20 on each page by placing the vector in the session.. it works for me
------------------
IBM Certified WebSphere Application Server V3.5 Specialist


regards,<br />Dharmesh Chheda
sumit malik
Greenhorn

Joined: Oct 31, 2001
Posts: 21
Originally posted by Dharmesh Chheda:
get all the records and place it in a vector and then display 20 on each page by placing the vector in the session.. it works for me

thankx dharmesh but i dont want to use arrays or vectors or any other collection as i dont want to increase the overhead on the server side so please tell me any other way..
Dharmesh Chheda
Ranch Hand

Joined: May 08, 2001
Posts: 204
Well then does your database table have any primary key?.. if yes then you can fetch the records as and when needed.
------------------
IBM Certified WebSphere Application Server V3.5 Specialist
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

There is a good discussion on the problem here
Dave
sumit malik
Greenhorn

Joined: Oct 31, 2001
Posts: 21
Originally posted by Dharmesh Chheda:
Well then does your database table have any primary key?.. if yes then you can fetch the records as and when needed.

yes the table from which i am retreiving the records contains foreign key to the master table but in the transaction table i don't have one and finally i am using transaction table only in my Query.So please suggest me how to move further.And also tell me how to use primary key for retreiving records.
Dharmesh Chheda
Ranch Hand

Joined: May 08, 2001
Posts: 204
See sumit
if you have a primary key then what you can do is set the fetchsize i.e. the statement Objects fetchsize using " stmt.setFetchSize(20); "
display the whole resultset which will only contain 20 records then in the while loop in which you display the records check whether the record you are printing is the last record by using
"restSetObject.isLast()"
is yes then save the primary key field or the unique field value for that record in a variable and pass it onto the next page by giving a URL as <NEXT> and append the last value to the URL.. on the next page set the fetch size to 20 again , display the records where <primarykeyfield> is greater than the passed value in the URL and get the next 20 records... after that keep calling the same page again and again.
a tradeoff will be that there will be many database calls.. cause for fetching records the database call has to be made .. but i think you will want this cause you dont want to fetch all the records and store it in the vector...
reply back ..

------------------
IBM Certified WebSphere Application Server V3.5 Specialist
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
David O'Meara
The link u have given is not working. Can you please update the link
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

After three years I'm not surprised the link is not valid.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
Yes, I agree.
I would really appreciate if you could update that link or provide some info on how to achieve this functionality.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Search further through this forum and the Servlets forum. It has been discussed dozens of times.
Murthy Cherukumilli
Ranch Hand

Joined: Aug 05, 2004
Posts: 45
hi sumit,

first thing i understood is that you have the jdbc code in the jsp? is that true? if yes then once you get the result set you can set all the data into a obj array of javascript and then using DHTML you can show 20 records at a time.

but if you are using a servlet in the path then what you can do is generate a javascript object from the result set that you get and send it to your jsp and you can use that with dhtml again.


Thanks<br />Murthy (SCJP 1.4 , SCWCD 1.4)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Getting DHTML involved is a poor idea. The paging of the data should be handled cmpletely on the server side.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,

Instead of storing 200 records or setFetchSize = 20, what you can do is select first set 20 records and display in the jsp and clicking the next button select the next set of records and similarly for previous values. What you need to store in the startIndex in a session object.

Regards,
M.S.Raman
Murthy Cherukumilli
Ranch Hand

Joined: Aug 05, 2004
Posts: 45
true but i thought the issue was not to load the server ....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

true but i thought the issue was not to load the server ....


I fail to see how getting DHTML involved removes any load from the server.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to use NEXT and Previous