Here is a minimal example to describe the problem:
Suppose a table is read from SQLiteDB and stored in a Java Collection object
DB Table ---> Java Object
idRecord | Data (table stored at DB) 1 One 2 Two 3 Three 4 Four
And through the sqlite jdbc library:
Map objTable = new HashMap (); // ... adding some jdbc stuff, we get a copy of DBTable in objTable
Then, if the object is modified, thereby.
idRecord | Data (modified table stored at objTable) 2 Two 4 FourModified 5 Five
(id 1 and 3 were deleted, 2 remained unchanged, 4 changed and 5 added)
Java Object -> DB Table (here's the question ...)
How to update / merge an object table using a database?
Why do I want to join, and not just save the object in a table ?
I think that if the table is large enough, then it makes no sense to write all the records, if only some of them have been changed.
Delete the entire DBtable and in a loop (dangerously the same), go through the object to write a new table.
Read the DBtable in the second java obj, and then compare both (with some alghoritm merge) and apply the actions (ADD, DELETE, MODIFY) directly to the DB. (I would recommend a recommendation for this comparison algorithm)
EDIT: Do not create the collection in the first place, read and write directly from the database, transmit requests through JDBC all the time
Another best approach
Thanks4Reading
source share