Why do I get an error when trying to sum the values ​​of a column retrieved in a ResultSet?

advertisements

whats wrong with my codes? I think its in the SQL but I don't know why. thank you in advance

try{
    clsConnect c = new clsConnect();
    Connection conn = c.makeConnection();
    Statement statement = conn.createStatement();
    String display = "SELECT SUM(Amountpaid) from mofficetbl";
    ResultSet rs = statement.executeQuery(display);
    while(rs.next()){
        totalTF.setText(rs.getString("Amountpaid"));
    }
}
catch (SQLException e) {
    JOptionPane.showMessageDialog(null, e);
}


You are selecting SUM(amountpaid) and trying to access the column amountpaid, but that column doesn't actually exist in the ResultSet Try rs.getString(1) or giving the SUM a name in the select as SELECT SUM(amountpaid) as sum from msofficetbl then doing rs.getString("sum");