dcsimg
How to show results page by page
5 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sarada_Lakhamraju
Posted On:   Tuesday, November 26, 2002 10:33 AM

Hello All,

I have a question regarding showing the results of a query page by page. I am using Java Servlets to get the information from html page and using JDBC to query the database. Now I want to display the results 10 records per page and have next link at the bottom to navigate to next page by page, how can I acheive this?? is this done with javascripting ??

Thanks,

Sarada

Re: How to show results page by page

Posted By:   Gautam_Marwaha  
Posted On:   Thursday, November 28, 2002 04:18 AM

See: http://www2.theserverside.com/resources/article.jsp?l=DataListHandler

Re: How to show results page by page

Posted By:   Nitesh_Naveen  
Posted On:   Thursday, November 28, 2002 02:24 AM

I hope you must've already got quite a few options here... all of them server side based. However it is not true that you cannot do it using Javascript. it can be done... To put it in simple terms, you need to put the results into javascript arrays (or javascript object arrays if you have more than one parameter to store per result). The results will be shown within a div tag and on click of next or previous you just build the results display and change the content of the div. This makes it easy to display the results without hitting ther server each time thus making the application faster, but it takes longer time to load the page.

The best option is to use a combination of the two - if the resultset is too large get it in chunks of smaller resultsets from your server side and split that into sets of 10 each in javascript

Re: How to show results page by page

Posted By:   Brian_Glodde  
Posted On:   Tuesday, November 26, 2002 12:06 PM

There are several ways to do this, none include javascript. And I might add this is not an easy technique to apply correctly. In most cases, this is done with a querystring (page.jsp?pg=1&psize=10) and one of the following techniques.


1.) If you're using a database such as mySQL, you can create a temp table via SQL statement. Explaining this technique would eat up the entire page, so instead check out this link that describes it nicely. This is an ASP example, but the same theories apply whether doing it in a stored proc or doing it with a straight SQL call and in whatever scripting language being used. This is also the fastest and most efficient way of pagination.


2.) When faced with a database that does not support the creation of temp tables (like Interbase/Firebird!), then another possible solution is to create vectors ( or arrays, whichever you like ) in your java code that hold the queried data, then you can loop around and send back only the data that is pertinent to the call (ie Page is 2, Amount of records is 10, so we would loop to element 11 push back elements 11 - 20). This data structure should be kept at the session level so requerying won't be necessary.


3.) Use an existing framework to get the job done. There are many taglibs out there that can most of this up for you.

ยป Jakarta Taglibs - Page 1.0


Hope that helps!

Re: How to show results page by page

Posted By:   Steven_Martin  
Posted On:   Tuesday, November 26, 2002 11:58 AM

this is a common coding job that you have to do yourself. I would think about what pagination requires. I haven't seen a tag library on this.



If you run into a problem please post it and I'll help.

Re: How to show results page by page

Posted By:   Thomas_Hackel  
Posted On:   Tuesday, November 26, 2002 11:39 AM

this has nothing to do with javascript. store the resultset in the session, and when you press next/prev run the next 10 rs.next()/rs.previous() and display the data. but this is NOT a good way, because inside the resultset there is a db connection which wastes resources as hell (dbconnections are a critical resource!!!). you will see, when more users connect to the servlet you will encounter nice sql exceptions.
an other way is to use proprietary sql commands like LIMIT (MySQL), but then you can use only one database which supports this, others are excluded. there are more solutions for this, but i hope this could give you a clue.
About | Sitemap | Contact