aspose file tools*
The moose likes JDBC and the fly likes How to retrive  data two times from database in sinble jsp page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to retrive  data two times from database in sinble jsp page." Watch "How to retrive  data two times from database in sinble jsp page." New topic
Author

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

Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
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

Joined: Jul 22, 2008
Posts: 3
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 29, 2008
Posts: 151
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

Joined: May 29, 2008
Posts: 151
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

Joined: May 29, 2008
Posts: 445

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 ]

Never try to be a hard-worker. Be a smart-worker.
My Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrive data two times from database in sinble jsp page.