尝试对ResultSet中检索的列的值求和时为什么会出现错误? [英] Why do I get an error when trying to sum values of a column retrieved in a ResultSet?

查看:81
本文介绍了尝试对ResultSet中检索的列的值求和时为什么会出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有什么问题?我认为它在SQL中,但我不知道为什么.预先谢谢你

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

推荐答案

您正在选择SUM(amountpaid)并尝试访问列amountpaid,但是该列实际上不存在于ResultSet中.尝试rs.getString(1)或在选择中为SUM命名为SELECT SUM(amountpaid) as sum from msofficetbl,然后执行rs.getString("sum");

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");

这篇关于尝试对ResultSet中检索的列的值求和时为什么会出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆