当我通过带有所有Jcomponats值的click事件按钮时,它不会更新我的表,而是更新其他表中的代码,从而反映异常?
private void update() {
String id = txtPcno.getText();
String updateQuery = "insert into n_patient (name, gender, NRIC, nationality, height, weight, smoke, last_seen) values(?,?,?,?,?,?,?,?)";
try {
pst = con.prepareStatement(updateQuery);
//pst.setString(1, txtPcno.getText());
pst.setString(1, txtName.getText());
pst.setString(2, txtGender.getText());
pst.setString(3, txtNRIC.getText());
pst.setString(4, txtNationality.getText());
pst.setString(5, txtHeight.getText());
pst.setString(6, txtWeight.getText());
pst.setString(7, txtSmoke.getText());
pst.setString(8, txtLastSeen.getText());
int rowAffected = pst.executeUpdate();
JOptionPane.showMessageDialog(null, String.format(" %d Modified Records Are Saved ", rowAffected));
clear();
} catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
您收到此异常是因为,
在向该表中插入记录时,您不会为那个('Pcno')列插入数据,并且该列具有诸如'not nullable'和'primary key'之类的属性。