以编程方式插入行(父级和子级) [英] Insert rows (parent and children) programmatically

查看:69
本文介绍了以编程方式插入行(父级和子级)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring和JDBCTemplate.

I am using Spring and JDBCTemplate.

该方案是一个CUSTOMER表和ORDERS表-父子关系.

The scenario is a CUSTOMER table and ORDERS table - parent-child relationship.

我想进行插入(例如1个客户和5个订单)-但我不确定如何以编程方式在CUSTOMER表中插入一行(某些如何获取Oracle生成的唯一ID),然后插入子表ORDERS中对应的5行,其中包含由客户插入内容创建的唯一ID.这个唯一的ID显然维护了客户与其订单之间的关系.

I want to do an insert (for example 1 customer and 5 orders) - but I am unsure how you programmatically insert a row in the CUSTOMER table (some how get hold of the Oracle generated unique id), and then insert the corresponding 5 rows in the child table, ORDERS, with the unique id created by the customer insert. This unique id obviously maintains a relationship between a customer and their orders.

非常感谢任何帮助.

PS-使用示例SQL编写有关如何在Spring Framework中完成此操作的代码将是很棒的-有点粗略,仅是为了给我提供基本概念.

PS - Code with example SQL on how this is done in Spring Framework would be fantastic - something fairly rough just to give me the basic idea.

推荐答案

检查

Check the update method in JDBCTemplate whcih takes a KeyHolder object. After execution that Keyholder objects contains the generated key.

Spring文档提供了用法示例这里.

The Spring documentation has an example of usage here.

这篇关于以编程方式插入行(父级和子级)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆