我的代码是这样的
ResultSet rs = statement.executeQuery(
"SELECT SUM(column1) FROM table where column2=name ");
system.out.println(rs)
那是对的吗?或者我如何从 Java 中的 SQL 列中获取总和值?你能写一个小例子吗?
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));
}