使用java将一定数量的记录提交到DB
我在数据库中有表,例如TableOne。
根据某些规则,我应该将该表中的 N 条记录提交到其他表。
是否可以使用 jdbc 或 ResultSet 或 CachedRowSet 来做?
据我所知,初步流程:
1.循环遍历TableOne的ResultSet
2.如果满足特定条件,则增加计数器
3.如果不满足条件,则需要向其他数据库表提交N条记录=counter
4.提交这N条记录
所以,问题在第4步。
如何实施?
谢谢。
I have table in DB,e.g. TableOne.
By some rules i should commit N records from this table to other tables.
Is it possible to do with jdbc or ResultSet or CachedRowSet?
Preliminary flow, as i see:
1. loop through ResultSet
of TableOne
2. increment counter
if certain condition is met
3. if condition is not met, it's time to commit to other DB tables N records=counter
4. commit these N records
So,the question is in step 4.
How it may be implemented?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
计数器的用途尚不清楚,因此我假设您只是用它来说明您只提交与条件匹配的记录这一事实。
尝试构造一个完成所有工作的插入语句:
另一个选项是循环记录集并在每次满足条件时插入一条记录。您应该将循环包装在事务中,以便在循环完成之前不会提交任何内容。我的 JDBC 有点生疏,所以这里是一个伪代码示例:
第一种方法更可取,但可能在某些情况下无法在 SQL 表达式中确定条件。
The purpose of the counter is unclear, so I am going to assume that you are just using it to illustrate the fact that you are only committing records that match the condition.
Try constructing an insert statement that does all the work:
The other option is to loop over the record set and insert a record every time the condition is met. You should wrap the loop in a transaction so nothing gets committed until after the loop has completed. My JDBC is a little rusty so here is a psuedocode example:
The first approach is preferable, but there maybe some situations where the condition can't be determined within an SQL expression.