aspose file tools*
The moose likes JDBC and the fly likes Problem while displaying the LIst in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem while displaying the LIst in JSP" Watch "Problem while displaying the LIst in JSP" New topic
Author

Problem while displaying the LIst in JSP

shishir choubey
Greenhorn

Joined: Aug 05, 2008
Posts: 4
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

Joined: Feb 28, 2007
Posts: 1707
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.


cmbhatt
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

See the JSP FAQ for a discussion of this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
shishir choubey
Greenhorn

Joined: Aug 05, 2008
Posts: 4
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

Joined: Feb 28, 2007
Posts: 1707
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

Joined: Oct 14, 2008
Posts: 5
"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

Joined: Oct 14, 2008
Posts: 5
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

Joined: Oct 14, 2008
Posts: 5
There must be something wrong with me today!
A ")" should be following "rownum <=20".
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Howdy fransis lin,

You can edit your post clicking this link:

To edit your first most post in this thread click here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem while displaying the LIst in JSP