I’m coding a java project that have a MySQL db connection, but i can affrod the user have an internet connection all the time, that’s the reason because the program needs a SQLite db.
The issue is that I need to synchronize both databases, but the MySQL database would act as a master database, while the SQLite database would be a slave database, so to speak. This means that when the user runs the program, it should connect to both databases and check whether the SQLite database is empty or not. If it is empty, it should populate the SQLite database with the information from the MySQL database. However, if the SQLite database is not empty, the program should retrieve all the information from both the MySQL and SQLite databases and compare the data between them. I suggest this be done using tables, comparing the information in each row of the two tables, and if any records do not match, the SQLite database should be updated accordingly. Once the comparison and update of the SQLite database is complete, the program should close the connection to the MySQL database (to avoid overloading the database server) and start using the SQLite database.
The MySQL database should take priority over the SQLite database, but when a change is made to the SQLite database (once the synchronization has taken place), all changes made after synchronization should be directly loaded into the MySQL database (establishing a temporary connection to the server).
The problem is that I have no idea how to synchronize both databases.
By the way, this system is necessary because the program is designed for multiple users to access it, and it is intended for use in an office setting.
I would like to know if what I need is possible, and if it is, whether someone could show me an example or something similar to achieve my goal.
Thank you very much for reading my question.
PD:I’m aware that MySQL and SQLite are not completely compatible, but I plan to solve this through data conversion (manually converting the data within the program code to make it compatible between MySQL and SQLite, such as converting date fields to varchar for SQLite and vice versa).In another project, I’ve already done something similar by converting data to make it compatible with the database.