如何将 SQLite 数据库从 Android 复制到 MySQL 数据库(复制/同步) [英] How to copy SQLite database from Android to a MySQL database (replicate/sync)

查看:100
本文介绍了如何将 SQLite 数据库从 Android 复制到 MySQL 数据库(复制/同步)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 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.

  1. 使用 JSONObjectJSONArray 类创建数据的 JSON 对象.
  2. 将其作为字符串发布到您的 Web 服务 中,该字符串可能使用 PHP 或您喜欢的任何内容.
  3. 解析json并将数据插入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.

与从 MySQL 到 Android 相同:

  1. 创建以 JSON 格式显示数据的 Web 服务.
  2. 然后您必须请求该链接,您将获得 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.

  1. 安卓版
  2. 对于 PHP

如果有任何问题,您可以自由ping.

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

同步快乐.

谢谢.

这篇关于如何将 SQLite 数据库从 Android 复制到 MySQL 数据库(复制/同步)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆