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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>