Reputation: 3
When I pass the button on click event, with all Jcomponats value, It won't update my table instead of that It reflect exception while my code is working properly in other table?
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();
}
}
Here is the Image of indication Problem
Upvotes: 0
Views: 41
Reputation: 38
You are getting this exception because,
While inserting a record into that table, you do not insert data for that('Pcno') column and this column having a property like the 'not nullable' and 'primary key'.
Upvotes: 1