gpt4 book ai didi

java.sql.SQLException :field id does not have a default value

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

我正在使用 Java 和 MySQL 开发员工薪资管理系统。当我尝试添加记录时,会发生此错误。

我的代码在这里:

    try { 
String sql ="insert into Staff_information "
+ "(first_name,surname,Dob,Email,"
+ "Telephone,Address,Department,"
+ "Image,Salary,Gender,Address2,"
+ "Post_code, Designation,Status,job_title,Apartment,Date_hired) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_firstname.getText());
pst.setString(2,txt_surname.getText());
pst.setString(3,txt_dob.getText());
pst.setString(4,txt_email.getText());
pst.setString(5,txt_tel.getText());
pst.setString(6,txt_address.getText());
pst.setString(7,txt_dep.getText());
pst.setBytes(8,person_image);
pst.setString(9,txt_salary.getText());
pst.setString(10,gender);
pst.setString(11,txt_add2.getText());
pst.setString(12,txt_pc.getText());
pst.setString(13,txt_design.getText());
pst.setString(14,txt_status.getText());
pst.setString(15,txt_job.getText());
pst.setString(16,txt_apt.getText());
pst.setString(17,txt_doj.getText());
pst.execute();
JOptionPane.showMessageDialog(null,"Data is saved successfully");
} catch (Exception e) {
JOptionPane.showMessageDialog(null,e);
} finally{
try {
rs.close();
pst.close();
} catch(Exception e) {
JOptionPane.showMessageDialog(null,e);
}
}
}

最佳答案

您的表还有一个非空列id(可能是主键),没有默认值。这意味着您必须在查询中分配一个值。

这也可能意味着您打算将其设置为一个标识列 (AUTO_INCRMENT),但忘记将其设置为一个。

关于java.sql.SQLException :field id does not have a default value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42062677/

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