开发者

JDBC command to insert/delete/update multiple records?

开发者 https://www.devze.com 2023-04-12 16:54 出处:网络
suppose I have a table that has the following keys: 1 2 3 and then I get a new request (JSON list) to update that table with开发者_运维问答:

suppose I have a table that has the following keys:

1
2
3

and then I get a new request (JSON list) to update that table with开发者_运维问答:

2
4

The user wants me to delete 1 and 3. Keep (possibly update) 2 and add 4. I can write a bunch of code t loop and perform this operation but is there some automated JDBC command that will perform the merge for me?

Thanks.


my suggestion is to delete all previous rows and insert new rows. you just need to write 2 queries. 1) delete all previous rows 2) Insert new rows


You could use an ORM library like sormula that would do all of the work for you with deleteAll and insertAll methods.

Include deletes and inserts within a transaction if more than one thread may perform this at the same time.

If you wanted the "union" of old and new, sormula has save and saveAll methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号