两种方法:不知道你用哪一种? 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);
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);