December 24th, 2002, 11:29 AM
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;");
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?
December 25th, 2002, 01:55 AM
well this query should return only 1 tuple.
in the ResultSet results
so (i am assuming you have a PrintWriter out)
For More info on ResultSets
out.println("SUM PAID: " + results.getString(1) + "<br>"
+ "SUM TOTAL: " + results.getString(2));
December 30th, 2002, 09:51 AM
Yes that did it, thank you!
December 30th, 2002, 11:20 AM