我的代码有什么问题?我认为它在 SQL
中,但我不知道为什么。提前谢谢你
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);
}
最佳答案
当你调用这个select语句时;返回的列实际上称为“SUM(amountpaid)”而不是 amountpaid 因此要么将其别名更改为
"SELECT SUM(Amountpaid) as Amountpaid from mofficetbl"
您还可以:
rs.getString("Sum(Amountpaid)");
关于java - 为什么在尝试对 ResultSet 中检索到的列的值求和时出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30146968/