Press "Enter" to skip to content

Summation & average operation using java gui.

Source code of Summation & average operation in java gui.

  1. 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);
}

Interface of after run the page.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *