This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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

 
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
 
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.
 
Marshal
Posts: 25224
65
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
 
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 ]
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!