|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
Yes that did it, thank you!
|
|
#4
|
||||
|
||||
|
no prob
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > JSP MySQL question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|