• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while displaying the LIst in JSP

 
shishir choubey
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.
 
Chandra Bhatt
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
 
francis lin
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic