Results 1 to 4 of 4
  1. #1
    peccy is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default 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?

  2. #2
    peccy is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default 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?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,085
    Rep Power
    20

    Default 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.

    ** This space for rent **

Similar Threads

  1. update database
    By manuzerwa in forum New To Java
    Replies: 4
    Last Post: 04-01-2012, 12:35 AM
  2. Update table in database
    By CTheSky in forum JDBC
    Replies: 3
    Last Post: 01-30-2011, 04:18 AM
  3. Replies: 1
    Last Post: 09-27-2010, 12:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •