gpt4 book ai didi

java - 错误的整数值 :'javax. swing.JFormattedtextField

转载 作者:行者123 更新时间:2023-12-01 12:58:18 24 4
gpt4 key购买 nike

我有一个问题想请教你。我正在使用 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 的列路径

感谢您的阅读!

最佳答案

我注意到一些问题,

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.

关于java - 错误的整数值 :'javax. swing.JFormattedtextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23718385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com