Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Problem while displaying the LIst in JSP

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a problem while displaying the List in the jsp.
Say suppose i have 50 records in the DB and i want to display 10-10 records in the jsp with 'Next' and 'Previous' button.
for this scenario i do not want to keep the whole list in the cache. I want to query the DB each time when user click on the 'Next' or 'Previous' Button.

Please someone suggest me, how to achieve this in jsp.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just put the limit in the query like

SELECT * FROM <table_name> LIMIT 1,10

Next time the query will look like:

SELECT * FROM <table_name> LIMIT 11,20

and so on.

Now where to store the information, what level of paginated page is on
display. You can keep this information on the Session object.
 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JSP FAQ for a discussion of this.
 
shishir choubey
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the query suggested by you is not working in oracle.
Can somebody suggedt any other way to implement this.

Thanks in advance

Shishir
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oracle has a system attribute ROWNUM for each record returned. A query that
only returns the first 20 records would look like the one in the example.

select col from <table name> where rownum<=20;


See this link at JavaRanch
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"select * from ( select row_.*, rownum rownum_ from (select * from ( select row_.*, rownum rownum_ from (" + yourSql + " ) row_ where rownum <= " + endIdx + ") where rownum_ >" + beginIdx ) row_ where rownum <= " + endIdx + ") where rownum_ >" + beginIdx
 
francis lin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, there's some mistake in my first reply.

In the case of Oracle, use this:

"select * from (select row_.*, rownum rownum_ from (" + yourSql + " ) row_ where rownum <=20 where rownum_ >10"
 
francis lin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must be something wrong with me today!
A ")" should be following "rownum <=20".
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy fransis lin,

You can edit your post clicking this link:

To edit your first most post in this thread click here
 
It runs on an internal combustion engine. This ad does not:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic