Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

want to display results page by page

 
Rinku
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear sir,
i want to display 10 records per page from my data base
usinf JSP technology
i want to know, can i write any sql query for that or i have write seprate coding .
pls do send any coding you have that in this mail id rinkuraj@yahoo.com
thanks in Adavance
Rinku
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Rinku",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
 
Raja Shekhar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !!

There is no Query to display 10 records at a time..
Fetch all records...

and manage the 10 records...per ..page in JSP page...
Seeya

Raj
 
vikinsa
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take the problem like this way....
1. Start a counter..
int intCount=0;
2. Prepare a query and Fetch the resultset
String query="select name from emp";
ResultSet rs=stmt.executeQuery(query);
3. Retrive the values from the result set

while(rs.next())
{
String name=rs.getString("name");
if(count<10)
{
vctVector.addElement(name);
}
count++;
}

5. use vector as data source.
6. In the next ietration update the initial value of count to 10 and the value in the if loop to 20. This can be done dynamically.
Originally posted by Rinku:
Dear sir,
i want to display 10 records per page from my data base
usinf JSP technology
i want to know, can i write any sql query for that or i have write seprate coding .
pls do send any coding you have that in this mail id rinkuraj@yahoo.com
thanks in Adavance
Rinku


------------------
Vikas Aggarwal
Technology Associate
http://www.vikinsa.com
 
Deepak B
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear vikinsa
The solution u r givan for ritu problem will work with small amount of data but when u are acsseing huge data (may be 50000 or more than that) then u can't store data in to vector or collction, so how can i display records page by page.With ResultSet.

Thnx
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raja Shekhar:
There is no Query to display 10 records at a time..

Sure there is. To display records n through m for a query:
Standard SQL-92:
SELECT *
FROM tables a
WHERE whereclause AND
  (SELECT COUNT(*)
   FROM tables b
   WHERE whereclause AND
   b.orderby_fields < a.orderby_fields)
  BETWEEN n AND m
ORDER BY orderby_fields
Oracle:
SELECT *
FROM tables
WHERE whereclause AND
  ROWNUM BETWEEN n AND m
ORDER BY orderby_fields
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic