Paging Techniques & Logics

Hii Javaities

I am developing an application where i need to have pagination as i am retreiving records from databse...............

I need to know wht are the pagination techniques.....

I have already gone through other threads bu i m not clear with tht.

I want 2 know which is the best pagination technique.....

1) querying databse again & again (restricting rows by using rownum , user will be asked to enter the number of records he wants to view & then this number will be used in SQL query to restrict the rows)

2) Retreiving Records at once & then storing them in Collection Objects..........

In case if using Collection is good , can ayone provide me with a little code to start with.

Plz Share ur views...................

[797 byte] By [help_eachothera] at [2007-10-2 9:46:30]
# 1
http://www.servletsuite.com/servlets/pagertag.htm
avramucza at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hey FrndCan u plz tell me how to use the tags in my jsp.I am using Tomcat 4.1 .....
help_eachothera at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
To use tag libs u have to install Apache Tomcat 5.0 and also u have to install tag libs from jakarta site
SivaRamaKrishnaa at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Can taglibs be used in Tomcat 4.1...............?If yes can anybody tell me how 2 go abt it............
help_eachothera at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
can any body send me the simple code for pagination.actually i tried manier times doing this but was not able to do this..please dont refer any taglib fution since the taglib.tld file is not working properly...regards
chek_me_outa at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Dear,

One of the best way is

1. give UniqueID for Records in database

2. On search get the uniqueIDs of Results( according to supplied Criteria)

3. Fix page size (u can use property file), Say 20

4. get the details of First 20 rec and display

5. on next or prev set the index and get another 20 rec

Ganesh

GaneshNarayana at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
See this for example: http://www.servletsuite.com/tips/grid1.htm
dnamiota at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

if resultset is huge then it is better to use 1st method using rownum.otherwise u can use 2nd method.nyways i've implemented 2nd one.

first u take resultset in a arraylist n get the size of that arraylist.define a variable page size with required size.devide size of arraylist by pagesize.

u'll get no of pages required.each time increase page no n get start row n end row.

set pageNumber 0 .on each click of next increment it by 1 upto (size-1).

startRow = pageNumber*PAGE_SIZE ;

endRow = startRow + PAGE_SIZE - 1 ;

iterate a loop from start row to end row n get the desired data.

snehaa at 2007-7-16 23:51:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...