Brian Tkatch wrote:1) Please put the error message in the post. It took me a while to realize it was in the subject.
2) Try to run the statement yourself with the same values to help determine what might be failing.
3) The query is using dynamic SQL. That is generally insecure. Please consider using placeholders instead.
If i try it in workbench the code does work. weird.
again the code i got in my eclipse console:
This is the errror code :Cannot add or update a child row: a foreign key constraint fails (`orderapp`.`orderproducts`, CONSTRAINT `FK_orderID` FOREIGN KEY (`order_ID`) REFERENCES `orders` (`orderID`) ON DELETE NO ACTION ON UPDATE NO ACTION)
Kees deVries wrote:This is the errror code :Cannot add or update a child row: a foreign key constraint fails (`orderapp`.`orderproducts`, CONSTRAINT `FK_orderID` FOREIGN KEY (`order_ID`) REFERENCES `orders` (`orderID`) ON DELETE NO ACTION ON UPDATE NO ACTION)
So for some reason you are violating this constraint. Which values are you trying to insert? And what's the content of the orders table?
A few other remarks regaringd your code:
1/ (as Brian already mentioned) you should consider using prepared statements in order to prevent possible SQL injection attacks (and enjoy other benefits as well). More info about prepared statements can be found here.
2/ in the update method you are not closing the Statement resource. It's always a good practice to close your resources once they are not needed anymore.
It is sure that you are violating reference key rule. There are two column(fields) of the table, order_id and product_id. There is possibility that there is a null value coming from your front end code function and trying to insert into your data table but you have set Not Null constraint. It is better to print or observe the value of the each field through debug, you will definitely solve your problem.
Mobile app development and web development
I love a good mentalist. And so does this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners