问题
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 forward to 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 Webservice. 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.
Any help?
回答1:
Yes of course, its Sync.
You have to create Web Service for that.
Just follow some steps for sending data from Android to MySQL:
- Create
JSONobject of your data usingJSONObjectandJSONArrayclass. - post that as an string to your
Web Servicethat might be inPHPor whatever you prefered. - process to parse json and insert data in to
MySQLdatabase.
Same as from MySQL to Android:
- Create
Web Servicethat displays your data inJSONFormat. - 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.
- For Android
- For PHP
If there is any problem then you can free to ping.
Happy Syncing.
Thank you.
来源:https://stackoverflow.com/questions/18073806/how-copy-sqlite-database-from-android-to-a-mysql-database-replicate-sync