我的代码就像这样
ResultSet rs = statement.executeQuery(
"SELECT SUM(column1) FROM table where column2=name ");
system.out.println(rs)
这是对的吗?或者我如何从java中的SQL列中获取sum值?你能写一个小例子吗?
答案 0 :(得分:1)
ResultSet rs = statement.executeQuery(
"SELECT SUM(column1) FROM table where column2=name ");
System.out.println(rs);// this is wrong
这将打印ResultSet对象。
这应该是
ResultSet rs = statement.executeQuery(
"SELECT SUM(column1) FROM table where column2=name ");
if(rs.next()){
System.out.println(rs.getInt(1));
}