Java – insert rows programmatically (parent and child)
I am using spring and JDBC template
This scenario is customer table and orders table - parent - child relationship
I want to make an insert (for example, 1 customer and 5 orders) – but I'm not sure how you programmatically insert a row in the customer table (how to obtain the unique ID generated by Oracle), and then insert the corresponding 5 rows. In the sub table, orders, has the unique ID created by customer insertion. This unique ID obviously maintains the relationship between customer and order
Any help would be appreciated
PS – the sample SQL code on how to do this in the spring framework will be great – just to give me some basic ideas
Solution
Check the update method in the JDBC template, which takes the keyholder object After execution, the keyholder object contains the generated key
The spring documentation has a usage example here