Results 1 to 4 of 4
- 12-16-2012, 09:13 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
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?
- 12-16-2012, 09:39 AM #2
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
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?
- 12-16-2012, 01:12 PM #3
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-17-2012, 10:28 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.Please do not ask for code as refusal often offends.
Similar Threads
-
update database
By manuzerwa in forum New To JavaReplies: 4Last Post: 04-01-2012, 12:35 AM -
Update table in database
By CTheSky in forum JDBCReplies: 3Last Post: 01-30-2011, 04:18 AM -
Cannot add or update a child row: a foreign key constraint fails
By niteangell21 in forum New To JavaReplies: 1Last Post: 09-27-2010, 12:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks