#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Phoenix, AZ
    Posts
    2
    Rep 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?
  2. #2
  3. dont click here
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    409
    Rep Power
    13
    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/ap...ResultSet.html
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Phoenix, AZ
    Posts
    2
    Rep Power
    0
    Yes that did it, thank you!
  6. #4
  7. dont click here
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    409
    Rep Power
    13

    Thumbs up


    no prob

IMN logo majestic logo threadwatch logo seochat tools logo