不正确的整数值:'javax.swing.JFormattedtextField

时间:2014-05-18 03:50:45

标签: java sql swing

我有问题,想问你。我正在使用Netbeans,这是我的代码:

private void jButton_SuaActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        String sql ="update mathang set tenmathang = ?, donvitinh = ?, quycach = ?, dongiaban = ?, manhomhang = ? where mamathang = ?";
        String jF = jFormattedTextField_Dongiaban.getText();
        int i = Integer.parseInt(jF);
        //AbstractFormatter formatter = jF.getFormatter();
        try{
            pst =conn.prepareStatement(sql);
            rs =pst.executeQuery();
            pst.setString(1, jTextField_Tenmathang.getText());
            pst.setString(2, jTextField_Donvitinh.getText());
            pst.setString(3, jTextField_Quycach.getText());
            pst.setString(4, i);
            pst.setString(5, (String) jComboBox_Manhomhang.getSelectedItem());
            //jComboBox_Manhomhang.addItem(jTable_Mathang.getText());
            //pst.setString(5, jComboBox_Manhomhang.setSelectedItem());
            //(2, jComboBox_Manhomhang.getText());
            pst.setString(6, jTextField_Mamathang.getText());
            pst.executeUpdate();
            JOptionPane.showMessageDialog(null, "Đã cập nhật bảng  < MẶT HÀNG >");
            UpdateMathang();
        }catch(SQLException | HeadlessException e){
            JOptionPane.showMessageDialog(null, e);
        }
    } 

错误是:java.sql.SQLException: integervalue:'javax.swing.JFormattedField[JFormattedField...layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignme'不正确 对于row1的列路径

感谢阅读!

1 个答案:

答案 0 :(得分:1)

我注意到一些问题,

pst =conn.prepareStatement(sql);
// rs =pst.executeQuery(); // <-- bind the parameters first!
pst.setString(1, jTextField_Tenmathang.getText());
pst.setString(2, jTextField_Donvitinh.getText());
pst.setString(3, jTextField_Quycach.getText());
pst.setInt(4, i); // <-- setInt - not setString()
pst.setString(5, jComboBox_Manhomhang.getSelectedItem()
    .toString()); // <-- call toString() instead of a cast.
//jComboBox_Manhomhang.addItem(jTable_Mathang.getText());
//pst.setString(5, jComboBox_Manhomhang.setSelectedItem());
//(2, jComboBox_Manhomhang.getText());
pst.setString(6, jTextField_Mamathang.getText());
pst.executeUpdate(); // <-- Looks good.