Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 24th, 2002, 11:29 AM
jrhoward jrhoward is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Phoenix, AZ
Posts: 2 jrhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
JSP MySQL question

I am new to JSP so please bear with me.

I have a JSP that hits a database and returns the stored values-- this part works fine. Two of my columns contain values for which I would like to display their sums. I know the SQL statement I would use looks something like this:
SELECT SUM(paid),SUM(total) FROM attendees;

I have a Java Bean taht holds all my database methods. The snippet (abridged) in question is the following:
Statement statement = con.createStatement();
ResultSet results = statement.executeQuery("SELECT SUM
(paid),SUM(total) FROM attendees;");
return results;

My problem is making the conceptual leap of getting the results from this query to display somewhere on my JSP. Does anyone have any thoughts on how to make this work?

Reply With Quote
  #2  
Old December 25th, 2002, 01:55 AM
Shocka's Avatar
Shocka Shocka is offline
dont click here
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 409 Shocka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 35 m
Reputation Power: 7
well this query should return only 1 tuple.

in the ResultSet results

so (i am assuming you have a PrintWriter out)

Code:
if(results.next()){

  out.println("SUM PAID: " + results.getString(1) + "<br>" 
                 + "SUM TOTAL: " + results.getString(2));

}


For More info on ResultSets

http://java.sun.com/j2se/1.4/docs/a.../ResultSet.html

Reply With Quote
  #3  
Old December 30th, 2002, 09:51 AM
jrhoward jrhoward is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Phoenix, AZ
Posts: 2 jrhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes that did it, thank you!

Reply With Quote
  #4  
Old December 30th, 2002, 11:20 AM
Shocka's Avatar
Shocka Shocka is offline
dont click here
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 409 Shocka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 35 m
Reputation Power: 7
Thumbs up

no prob

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > JSP MySQL question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway