4

I am building an Android app which will take some data and images from user and store them in a local SQLite DB. What I am looking for is a way by which I can replicate this DB to a MySQL DB on my server.

I looked on the Internet for the answer but there isn't a proper solution to it. Though the most common answers I found were SymmetricDB and setting up a web service. I am still confused which route to take.

The SQLite DB may also at need, have to pull updated data from the MYSQL DB, so I guess the better word to use is Sync rather than Replicate.

halfer
  • 19,824
  • 17
  • 99
  • 186
Arihant
  • 3,847
  • 16
  • 55
  • 86

1 Answers1

8

Yes of course, its Sync.

You have to create Web Service for that.

Just follow some steps for sending data from Android to MySQL:

  1. Create JSON object of your data using JSONObject and JSONArray class.
  2. post that as an string to your Web Service that might be in PHP or whatever you prefered.
  3. process to parse json and insert data in to MySQL database.

Same as from MySQL to Android:

  1. Create Web Service that displays your data in JSON Format.
  2. then you have to Request to that link and you'll get JSON data, just you have to parse and store into SQLite.

You have to take care about Data Confiction. for that you have to take one that store some value both side like last sync date/time.

There are some tutorial that will help for android JSON Parsing and PHP JSON Parsing.

  1. For Android
  2. For PHP

If there is any problem then you can free to ping.

Happy Syncing.

Thank you.

Community
  • 1
  • 1
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • 2
    "You have to take care about Data Confiction" Indeed. It can take, let's say, five man-years of work to create a complete offline-online sync system. ie, what say realm.io or zumero does. – Fattie Dec 03 '16 at 15:08
  • 3
    Anyone reading this, do not take the two-way synchronization problem lightly. It starts with "I just need to fetch records from DB" and ends with a mess. if you are changing data at both ends, sync will have lot of hairy problems. – rjha94 Jul 12 '20 at 05:16