aspose file tools*
The moose likes JDBC and the fly likes Sever Error: Cannot update child Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Sever Error: Cannot update child" Watch "Sever Error: Cannot update child" New topic
Author

Sever Error: Cannot update child

Luis Villamarin
Greenhorn

Joined: May 24, 2012
Posts: 21

Hello,

I'm trying to store data to from a registration form (html). everything runs smoothly until I try to store the the Foreign Keys. When I test the form I get the following error:

SEVERE: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`ebooksalesdb_schema`.`user`, CONSTRAINT `fk_user_account_type1` FOREIGN KEY (`account_type_account_name`) REFERENCES `account_type` (`account_name`) ON DELETE NO ACTION ON UPDATE NO ACTION)

After running the application the stack trace indicates that the error is located at:
at eBooks.data.UserDB.insert(UserDB.java:47)
at eBooks.controller.RegisterUserServlet.doPost(RegisterUserServlet.java:71)



This is the code for the RegisterUserServlet:



This is the code for the UserDB class:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Luis Villamil wrote:CONSTRAINT `fk_user_account_type1` FOREIGN KEY (`account_type_account_name`) REFERENCES `account_type` (`account_name`)

That part means that each value that you put into the account_type_account_name column of this table, must have a matching value in the account_name column of the account_type table. Make sure that's the case.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Luis Villamarin
Greenhorn

Joined: May 24, 2012
Posts: 21

Could this be that the FK was not properly created when the DB/Table was created?
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Luis Villamil wrote:Could this be that the FK was not properly created when the DB/Table was created?


quite likely, we have given you the name and the contents of the index, go and investigate your database see if that is what was wanted on it.
Luis Villamarin
Greenhorn

Joined: May 24, 2012
Posts: 21

Hi I worked on the database and effectively there was a relationship that was not correctly set. However, what I did, didn't fully fixed the problem this what I'm getting now as an error:


SEVERE: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`ebooksalesdb_schema`.`user`, CONSTRAINT `fk_user_account1` FOREIGN KEY (`account_account_id`, `account_account_type_account_name`) REFERENCES `account` (`account_id`, `account_type_account_na)

I noticed that at the end of the error it says `account_type_account_na, instead of `account_type_account_name'). I checked for the name inconsistency and couldn't find anywhere that `account_type_account_na. Could this be the reason ?


I rebuilt the database and I'm still getting the same error.

Do you have idea why this keeps on happening?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sever Error: Cannot update child