Fetchig first 11 to 20 records from 100 records in a select

i need to fetch 11 to 20 records from total 100 records on click of a button.

Initially i will be displaying 1 to 10 records and on click of a button i need to fetch from 11 to 20 . Any direction would be greatly helpful.

I can fetch all the 100 records and keep in session, but i want to avoid using much memory in session

TIA

[352 byte] By [Funnya] at [2007-11-26 14:38:37]
# 1
I did not quite understand ur ques..u mean to say that every time u press button it shud display the next 10 records..is that what u want?
KayDeEa at 2007-7-8 8:19:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Yes exactly, on click of button i should get next 10 records from the database
Funnya at 2007-7-8 8:19:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Hi Funny,Use setFetchSize() method.This will limit the number of records to be fetched.Regs
sdnusra at 2007-7-8 8:19:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

but setFetchSize() just limits the number of records to be fetched, but my question was how to move to the 11 th record.

Can i try using resultset.relavtive(11) method to move the cursor postion and then fetch the next 10 rows.. i will any way try out that , but any suggestions are greatly welcome...

TIA

Funnya at 2007-7-8 8:19:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

Hi Funny,

So you are going to display first 10 recs.Then on click of 'Next' button, you will show next set of records(10)..rt?

If you insists that your query should contain an

ORDER BY 'somecolumn/s',

you can pass the last column value as a parameter to the next call to the query & you can frame a search criteria with that column value.

Regs

sdnusra at 2007-7-8 8:19:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

well as far myknowledge in this concern... pargination od data through database is supported by few databases only....

for examplein oracle one can use rownum

select * from emp where rownum>=0 and rownum<=10

now hold two value counter=10 & incremator=10 in session...

onclick of button increment the counter = counter + incrementor.....

similar use rownum() in SQL-SERVER

LIMIT & OFFSET inMYSQL & POSTGRESQL.....

If in case the database doesn't support pagination constructs create a PK incrementor.... and try using the same logic...

Hop this helps....

REGARDS,

RaHuL

RahulSharnaa at 2007-7-8 8:19:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

> for examplein oracle one can use rownum

> select * from emp where rownum>=0 and rownum<=10

> now hold two value counter=10 & incremator=10 in

> session...

> onclick of button increment the counter = counter +

> incrementor.....

You can't use rownum in this manner.

Check out this great AskTom article for a full explanation.

http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html

extract from that link here (but read it all - its v good)

ROWNUM is a pseudocolumn (not a real column) that is available in a query. ROWNUM will be assigned the numbers 1, 2, 3, 4, ... N, where N is the number of rows in the set ROWNUM is used with. A ROWNUM value is not assigned permanently to a row (this is a common misconception). A row in a table does not have a number; you cannot ask for row 5 from a table梩here is no such thing.

Also confusing to many people is when a ROWNUM value is actually assigned. A ROWNUM value is assigned to a row after it passes the predicate phase of the query but before the query does any sorting or aggregation. Also, a ROWNUM value is incremented only after it is assigned, which is why the following query will never return a row:

select *

from t

where ROWNUM > 1;

Because ROWNUM > 1 is not true for the first row, ROWNUM does not advance to 2. Hence, no ROWNUM value ever gets to be greater than 1.

The article also explains how you can use rownum for pagination.

phawdona at 2007-7-8 8:19:42 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...