Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Weird error

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JSP/Servlet to develop a Web application...I had a table had 17 fields..At the first form user wants to fill only 8 forms..Whereas the table has 3 foreign key fields and user left one of them...When i try to insert the foreign key value which the user left, by storing the word "NULL" in a string and add it by ps.setString(10,var).. it compiles but it shows a weird error says

: Code Edited :
Ranchers, please let me know whats the problem and help me fix this error....
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Cannot add or update a child row: a foreign key constraint fails
(`raj1/tbl_rmadetails`, CONSTRAINT `fk_raj1tbl_vendortbl` FOREIGN KEY (`VENDOR_I
D`) REFERENCES `tbl_vendor` (`vendor_id`) ON DELETE NO ACTION ON UPDATE NO ACTIO
N)"

Your insert or update action violates this foreign key. I would assume that whatever your are inserting does not have a vendor_id, but if you check what that FK requires you should be able to work out what is missing.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock:

Your insert or update action violates this foreign key. I would assume that whatever your are inserting does not have a vendor_id, but if you check what that FK requires you should be able to work out what is missing.


How to find what the FK needs?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This depends on your database and the database tools you have. Which are you using?
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use MySQL.... and JSP/Servlet as my dev tool...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think mysqldump will show you the DDL for a foreign key. You could try that.
 
Revanth reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic