Cant update the database because of a foreign key
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try{
String value=rating.getSelectedItem().toString();
String value1=cuisine.getSelectedItem().toString();
String value2=style.getSelectedItem().toString();
String sql = "Insert into restaurant r (id,name,rating,id_cuisine) values (?,?,?,?) ";
pst = conn.prepareStatement(sql);
pst.setString(1, id.getText());
pst.setString(2, Name1.getText());
pst.setString(3, value);
pst.setString(4, value);
pst.executeUpdate();
}
catch(Exception e){
System.out.println("no work");
}
}
id_cuisine is a foreign key to another table and when i try to add new data it works on all fields except id_cuisine, how do i fix this?
Cant update the database because of a foreign key
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try{
String value=rating.getSelectedItem().toString();
String value1=cuisine.getSelectedItem().toString();
String value2=style.getSelectedItem().toString();
String sql = "Insert into restaurant r (id,name,rating,id_cuisine) values (?,?,?,?) ";
pst = conn.prepareStatement(sql);
pst.setString(1, id.getText());
pst.setString(2, Name1.getText());
pst.setString(3, value);
pst.setString(4, value1);
pst.executeUpdate();
}
catch(Exception e){
System.out.println("shit");
}
}
i cannot add data to the foreign key id_cuisine how do i fix this?
Re: Cant update the database because of a foreign key
Kindly go through the Forum Rules, particularly the second paragraph. I've merged the two threads you started in Advanced Java and NetBeans and moved them here, although it seems to me that this is a database rather than a JDBC question.
Please don't double post again.
db
Re: Cant update the database because of a foreign key
What does "it works on all fields except id_cuisine" mean?
Are you getting errors or what?
And please wrap your code in [code] tags [/code] so it retains its formatting.
Unformatted code is hard to follow.