I am using the jdbc connectivity with mysql. I am inserting data into one table and getting its primary key 'transactionid'. Now insert data with transactionid into another table.I am writing the code..\[code\]if (connection != null) { System.out.println("Now connection is created successfully"); stmt=connection.createStatement(); Date date=new Date(); DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"); String time=formatter.format(date); System.out.println("time is "+time); //insert transaction id and minimum support.... mySql = "insert into Transaction (minimumsupport) values('"+minimumSupport+"')"; stmt.executeUpdate(mySql,Statement.RETURN_GENERATED_KEYS); ResultSet rt=stmt.getGeneratedKeys(); int transactionId; while(rt.next()){ transactionId=rt.getInt(1); System.out.println("the transaction id is: "+transactionId); } rt.close(); int i; Statement stmt1; for(i=0;i<productArray.length;i++) { stmt=connection.createStatement(); System.out.println("first value: "+productArray); mySql = "insert into Producttransaction(transactionid,productId) values('"+transactionId+"','"+productArray+"')"; stmt.executeUpdate(mySql); status="productAdded"; System.out.println("product added"); } //To insert the data into the tables.... connection.close(); \[/code\]Exception:-And i am getting this exception..Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (\[code\]aprioridb\[/code\].\[code\]Producttransaction\[/code\], CONSTRAINT \[code\]fk_Productid\[/code\] FOREIGN KEY (\[code\]transactionid\[/code\]) REFERENCES \[code\]Product\[/code\] (\[code\]productId\[/code\]) ON DELETE NO ACTION ON UPDATE NO ACTION)