如何将 SQLite 数据库从 Android 复制到 MySQL 数据库(复制/同步) [英] How to copy SQLite database from Android to a MySQL database (replicate/sync)
问题描述
我正在构建一个 Android 应用程序,它将从用户那里获取一些数据和图像并将它们存储在本地 SQLite 数据库中.我正在寻找的是一种可以将此数据库复制到服务器上的 MySQL 数据库的方法.
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.
我在互联网上寻找答案,但没有合适的解决方案.虽然我找到的最常见的答案是 SymmetricDB 和设置 Web 服务.我还在迷茫走哪条路.
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.
SQLite DB 可能也需要,必须从 MYSQL DB 中提取更新的数据,所以我想使用更好的词是同步而不是复制.
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.
推荐答案
当然是,它的同步.
您必须为此创建Web Service
.
- 使用
JSONObject
和JSONArray
类创建数据的JSON
对象. - 将其作为字符串发布到您的
Web 服务
中,该字符串可能使用PHP
或您喜欢的任何内容. - 解析json并将数据插入
MySQL
数据库的过程.
- Create
JSON
object of your data usingJSONObject
andJSONArray
class. - post that as an string to your
Web Service
that might be inPHP
or whatever you prefered. - process to parse json and insert data in to
MySQL
database.
与从 MySQL 到 Android 相同:
- 创建以
JSON
格式显示数据的Web 服务
. - 然后您必须请求该链接,您将获得 JSON 数据,只需解析并存储到 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.
如果有任何问题,您可以自由ping.
If there is any problem then you can free to ping.
同步快乐.
谢谢.
这篇关于如何将 SQLite 数据库从 Android 复制到 MySQL 数据库(复制/同步)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!