• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 28333
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic