Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:52:24+00:00 2026-06-02T12:52:24+00:00

I have an application that I am working on that will query a database

  • 0

I have an application that I am working on that will query a database and display the results. The program also makes changes to the database (update, delete, insert). I had most of these features working correctly until recently when I made some changes. Now I am getting an SQLException that tells me I am violating a foreign key constraint. I have looked it up and found out that the violation is a result of more than one table sharing data. Is there a way to overcome this? How would I make the update without violating the constraint? here is my update method:

InstructorEditorPanel updateEditorPanel = new InstructorEditorPanel();

updateEditorPanel.setFieldText(InstructorEditorPanel.FieldTitle.B_NUMBER, updBNumber);
updateEditorPanel.setFieldText(InstructorEditorPanel.FieldTitle.FIRST_NAME, updFName);
updateEditorPanel.setFieldText(InstructorEditorPanel.FieldTitle.LAST_NAME, updLName);


int result = JOptionPane.showConfirmDialog(null, updateEditorPanel,
              "Update Instructor",        JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);
  if(result == JOptionPane.OK_OPTION)
  {
      for (InstructorEditorPanel.FieldTitle fieldTitle :    InstructorEditorPanel.FieldTitle
                 .values()) {

                    bNum =    getBNumber(updateEditorPanel.getFieldText(fieldTitle.values()[0]));
                    fName = getFirstName(updateEditorPanel.getFieldText(fieldTitle.values()[1]));
                    lName =  getLastName(updateEditorPanel.getFieldText(fieldTitle.values()[2]));
                   }
      try
{
    connection = DriverManager.getConnection(URL);
    updateInstructor = connection.prepareStatement(
    "UPDATE Instructor SET BNUMBER = ?, FIRSTNAME = ?, LASTNAME = ? WHERE BNUMBER = ?");

}catch(SQLException sqlException){
    sqlException.printStackTrace();
    System.exit(1);
}//end catch
  try
{

    updateInstructor.setString(1, bNum);
    updateInstructor.setString(2, fName);
    updateInstructor.setString(3, lName);
            updateInstructor.setString(4,mNumber);

    updateInstructor.executeUpdate();
}catch(SQLException sqlException){
        sqlException.printStackTrace();
}//end of catch
finally
{
    close();
}//end 
  }


Display(panel); }

I had the method working without any problems until recently when I made some changes. I don’t know what I did, but now I am getting the foreign key constraint violated exception

here is the exception:java.sql.SQLIntegrityConstraintViolationException: UPDATE on table ‘INSTRUCTOR’ caused a violation of foreign key constraint ‘SQL120408141918440’ for key (1234500000). The statement has been rolled back.

database info

CREATE TABLE Instructor (
BNumber varchar(10) NOT NULL,
FirstName varchar(20),
LastName varchar(30),
PRIMARY KEY (BNumber)
);

CREATE TABLE Section (
CRN int NOT NULL,
Term varchar(6) NOT NULL,
SectionNumber varchar(3),
CourseID varchar(9),
Enrollment smallint,
BNumber varchar(10),
PercentResp numeric(5,2),
CONSTRAINT CRN_Term PRIMARY KEY (CRN,Term),
FOREIGN KEY (CourseID) REFERENCES Course (CourseID), 
FOREIGN KEY (BNumber) REFERENCES Instructor (BNumber)
);

INSERT INTO Instructor (BNumber, FirstName, LastName)
VALUES 
('0000012345','Bill','Smith'),
('0000023456','Sue','Taylor'),
('0000034567','Skilar','Ramsey'),
('1234500000','Sam','Jones'),
('2345600000','Tyson','Quilez');

INSERT INTO Section (CRN, Term, SectionNumber, CourseID, Enrollment,
                 BNumber, PercentResp)
VALUES 
(40035,'201040','02B','CHM2210', 31,'0000034567',100),
(40001,'201040','02B','CGS1000', 27,'0000012345',100),
(40002,'201040','70B','CGS2100', 25,'0000012345',100),
(40003,'201040','71B','CGS2100', 19,'0000012345',100),
(40004,'201040','01B','COP1000', 15,'0000012345',100),
(40030,'201040','01B','BSCC1005',30,'0000023456',100),
(40031,'201040','02B','BSCC1005',25,'0000023456',100),
(40032,'201040','70B','BSCC1005',24,'0000023456',100),
(40000,'201040','01B','CGS1000', 15,'0000012345',100),
(40034,'201040','01B','CHM2210', 27,'0000034567',100);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:52:34+00:00Added an answer on June 2, 2026 at 12:52 pm

    Replace

    "UPDATE Instructor SET BNUMBER = ?, FIRSTNAME = ?, LASTNAME = ? WHERE BNUMBER = ?"
    

    With

    "UPDATE Instructor SET FIRSTNAME = ?, LASTNAME = ? WHERE BNUMBER = ?"
    

    You should not update the primary key if it’s the matching condition in your update query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an application that will have attachments, and I would like to
I'm working on a web application that will have a custom UI for the
I am working on a mysql query that will search a database of entries
I'm working on application in Java that will maintain database of song lyrics in
I have an application that is working as a proxy using QTcpSocket to intercept
I have a web application that I'm working on for work and its not
I have a .net application that is not working on a colleagues computer (he
I have a Core Data based mac application that is working perfectly well until
I have a small VB.NET application that I'm working on using the full version
I have a usercontrol in an asp web forms application that I am working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.