Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retrive data two times from database in sinble jsp page.

 
Harshal Gurav
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to retrieve data from table in two times.
In first query I am displaying all data available in table.
Now I want to count the no. Of rows available in the same table by using select count(*)from table-name type query.
How can I retrieve records of same table by firing these two queries in single jsp page :
Please Tell me how to execute to query un single jsp page.
Here is an page where i able to fired the single query to display the table
:





Thanks in advance
.................
Harshal
 
Saicharan velury
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi harshal
from your query and code displayed i understand that you are trying to display the details of a particular question from the question table.

you have done one part that is displaying the details from a table which is your first doubt

solution to your second doubt is quite simple
create another Statement st1 and another ResultSet rs1
now in the same jsp after you have closed the existing st and rs
<code>
st1.executeQuery("select count(*) from question");
int count=0;
while(rs1.next())
{
count=rs1.getInt(1);
}
out.println(count);
</code>

i am sure this will give you the count of the questions in the same jsp page.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just count the rows as you process them? Then you would not need to do that second query.
 
Harshal Gurav
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi saicharan,
Thank you very much for your post.
you suggested code is worked fine with given output as no of question in
that particular question bank.
Regards
Harshal
 
Harshal Gurav
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am Trying to pass an integer value that is an no. of row of table to next jsp page. for that i am trying to convert int value to string format but showing error in marked lines:

Kindly suggest me an updated code.
Thanks and Regards
Harshal
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it the actual code that you use.. If so then it's simple... Your code is like this


Just open and close the scriplet tags in proper place like the below one...



Just look at the code that is in BOLD... It use proper scriplets... Hope you will be clear in future..
[ July 23, 2008: Message edited by: Rajkumar balakrishnan ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic