0
我正在使用jtable和rs2xml.jar庫從jtable計算行的總和
我的表有3列。 ID,名稱,金額 我想計算金額欄的總和。
這裏是代碼:
//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> = 3」 這是什麼意思?爲什麼它不工作?
是的...我想念那個部分...謝謝 –