Source code of Summation & average operation in java gui.
- Summation code..
try{
String sql = "select sum(id) from user";
pst = con.prepareStatement(sql);
rs = pst.executeQuery();
if(rs.next()){
String sum = rs.getString("sum(id)");
jTextField_count.setText(sum);
}
}catch(SQLException e){
JOptionPane.showMessageDialog(null, e);
}
2. Average code…
try{
String sql = "select avg(id) from user";
pst = con.prepareStatement(sql);
rs = pst.executeQuery();
if(rs.next()){
String sum = rs.getString("avg(id)");
jTextField_count.setText(sum);
}
}catch(SQLException e){
JOptionPane.showMessageDialog(null, e);
}
Be First to Comment