Java 从jtable计算行的和

Java 从jtable计算行的和,java,swing,jtable,Java,Swing,Jtable,我正在使用jtable和rs2xml.jar库 我的桌子有三列。身份证、姓名、金额 我想计算金额列的总和 代码如下: //showcal is my table name try { Connection conn = getConnection(); PreparedStatement ps = conn.prepareStatement("select id,name,amoun

我正在使用jtable和rs2xml.jar库

我的桌子有三列。身份证、姓名、金额 我想计算金额列的总和

代码如下:

    //showcal is my table name
       try {

            Connection conn = getConnection();

            PreparedStatement ps
                    = conn.prepareStatement("select id,name,amount from income where idate=?");
      ps.setString(1,((JTextField) inpdatechosser.getDateEditor().getUiComponent()).getText());
            rset = ps.executeQuery();
            showcal.setModel(DbUtils.resultSetToTableModel(rset));


 //sum calculation
int total = 0;

    for (int i = 0; i < showcal.getRowCount(); i++){
        int amount = Integer.parseInt( showcal.getValueAt(i, 3).toString());
        total =total+ amount;
    }

jTextField1.setText(""+Integer.toString(total));

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
但什么也没发生。我得了3分
这是什么意思??为什么不工作???

表中的行和列索引是以零为基础的。所以第三列的索引应该是2,即:showcal.getValueAti,2

得到的异常意味着列的索引应该小于列数