java我从MySql得到异常,它不会更新表吗?
当我在click event上传递按钮时,所有Jcomponats值都为,它不会更新我的表,而是在我的代码在其他表中正常工作时,它会反映异常
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) 个答案