gpt4 book ai didi

java - 数据截断错误(列 item_code 的数据太长)

转载 作者:行者123 更新时间:2023-11-29 20:28:23 26 4
gpt4 key购买 nike

当我更新时,我得到

data truncation error (data too long for column item_codeat row #)

我在数据库中使用varchar(45)作为itemcode

String category="";

String item_code = txt_inventory_item_code.getText();

String item_name = txt_inventory_item_name.getText();

Format formatter = new SimpleDateFormat("yyyy-MM-dd");
String date = formatter.format(txt_inventory_date.getDate());

String expiry_date = formatter.format(txt_inventory_expiry_date.getDate());

int quantity=Integer.parseInt(txt_inventory_quantity.getText());

double unit_price=Double.parseDouble(txt_inventory_unit_price.getText());


try{
st = conn.createStatement();
String SQL = "Update inventory SET "
+ "item_code='"+txt_inventory_item_code+"',"
+ "item_name='"+txt_inventory_item_name+"',"
+ "date='"+formatter.format(txt_inventory_date.getDate())+"',"
+ "expiry_date='"+formatter.format(txt_inventory_expiry_date.getDate())+"',"
+ "quantity='"+txt_inventory_quantity+"',"
+ "unit_price='"+txt_inventory_unit_price+"' WHERE inventory_id Like "+txt_inventory_inventory_id.getText();
st.executeUpdate(SQL);

JOptionPane.showMessageDialog(null,"Updated Successfully");

}
catch (SQLException | HeadlessException e)
{
JOptionPane.showMessageDialog(null,e);
}

最佳答案

独立于有一些弱点的代码,我建议验证模型实体的不同字段,具体取决于数据库表上相应列的限制。希望这有帮助。

关于java - 数据截断错误(列 item_code 的数据太长),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39176680/

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