如果我用SQL语句统计某一列的总和,它的总和如何在程序中打印输出?

解决方案 »

  1.   

    做个for循环不行吗?或者就直接用对象去取值,System.out.println(内容)打就可以
      

  2.   

    写个sum(列字段) 最后用System.out.println()打出来看看就知道了
      

  3.   

    两种方法:不知道你用哪一种?
    strSql="select sum(rowName) total from tableName";
    --select sum(列名) total from 表名
    ResultSet rs = stmt.executeQuery(strSql);
    int total=0;
    while(rs.next()){
    total=rs.getInt("total");
    System.out.println(total);
    }
    -------------------------------------
    第二种:
    strSql="select cnt(列名) total from 表名";
    ResultSet rs = stmt.executeQuery(strSql);
    int total=0;
    int cnt=0;
    while(rs.next()){
    cnt=rs.getInt("cnt");
    total=total+cnt;}System.out.println(total);