File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Weird error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Weird error" Watch "Weird error" New topic
Author

Weird error

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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


Never try to be a hard-worker. Be a smart-worker.
My Blog
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

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

Joined: Apr 14, 2004
Posts: 10336

This depends on your database and the database tools you have. Which are you using?
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

I use MySQL.... and JSP/Servlet as my dev tool...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I think mysqldump will show you the DDL for a foreign key. You could try that.
Revanth reddy
Ranch Hand

Joined: Oct 10, 2008
Posts: 52
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weird error