public double sumMoney(int orderid){
double totalmoney=0;
Connection conn=this.getConn();
String sql="select sum(totalmoney) as total from orderdetail where orderid=?";
try {
ps=conn.prepareStatement(sql);
ps.setInt(1, orderid);
totalmoney=ps.get
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return totalmoney;
}
如何获取聚合函数total的值
ResultSet rs = ps.executeQuery();
if(rs.next()){
totalmoney=ps.getDouble("total");
}
如下写法
public double sumMoney(int orderid){
double totalmoney=0;
Connection conn=this.getConn();
String sql="select sum(totalmoney) as total from orderdetail where orderid=?";
try {
ps=conn.prepareStatement(sql);
ps.setInt(1, orderid);
ResultSet res = pstmt.executeQuery();
if(res.next()){
double temp=Double.parseDouble(res.getObject(1).toString())
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return totalmoney;
}
otalmoney=ps.getdouble(total);
或者otalmoney=ps.getdouble(第几列);