Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy SQLite database from Android to a MySQL database (replicate/sync) [duplicate]

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.

like image 541
Arihant Avatar asked Feb 16 '23 16:02

Arihant


1 Answers

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.

like image 138
Pratik Butani Avatar answered Feb 27 '23 09:02

Pratik Butani