如何在JTable行中添加双精度类型值?

时间:2018-09-11 15:35:32

标签: java swing jtable netbeans-8

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)     
{                                         
    try {

        Connection c = DBconnection.conn();
        PreparedStatement ps = c.prepareStatement("SELECT * from menu where items=?");
        ps.setString(1, (String) jComboBox2.getSelectedItem());
        ResultSet rs = ps.executeQuery();           
        DefaultTableModel tbn = (DefaultTableModel) jTable1.getModel();

        Vector v = new Vector<>();
        v.add(jComboBox2.getSelectedItem());
       v.add(qty.getText());

此行之后,我需要添加类型为double的价格,我正在从数据库中获取价格。我需要知道该怎么做。请有人帮忙

        tbn.addRow(v);

我在这里计算总数。
            double total = 0;

        for(int i=0; i<jTable1.getRowCount(); i++)
        {
            double amount = Double.parseDouble(String.valueOf(jTable1.getValueAt(i, 2)));
            jTable1.getValueAt(i,1));
            total+=amount;
        }
        Ltot.setText(String.valueOf(total));
    } catch (Exception ex) {
        Logger.getLogger(pos.class.getName()).log(Level.SEVERE, null, ex);
    }


}                         *emphasized text*

0 个答案:

没有答案