1

I am developing an android application which have

  • SQLite on the mobile
  • MS SQL on the Windows server

I want the mobile data to sync with the MSSQL database whenever a new entry is added. The sync data should remain in the mobile and work even if the mobile internet is offline.

The MSSQL database will have two identical (same fields structure and fields name)

I need to develop synchronization between these DB in one way.

The mobile application doesn't have any options for editing.

If I change data from server then it should change data in android

Sync will run the first time the application is started plus I will like to provide a sync button.

How do I sync databases in Android?

I have found several things but I am at beginners level. I didn't find any samples. I tried the "http://programmerguru.com/android-tutorial/how-to-sync-remote-mysql-db-to-sqlite-on-android/" tutorial but it uses php and MSSQL.

I will appreciate if some one will give me some sample code with some explanation or something like that which will show me a way to do this.

4
  • hey u can add the last updated column in both the Table(MySql and Sqlite) from there you can match the data which is is changed and updated that row only Commented May 10, 2016 at 11:17
  • Can you direct me towards some sample code. Commented May 10, 2016 at 11:31
  • How much data are we talking about? Commented May 10, 2016 at 11:36
  • Not much. 2-3 tables with few thousand rows Commented May 10, 2016 at 15:33

1 Answer 1

1

First you need to write a sever side code which read the data from (MySQL database) and send it to mobile app, then you receive this data and add save (or update) it in(SQLite database). To inform the application about the new data you can make a global variable saved on the server (or create a new table to add this value). this value will be increased each time MySQL database updates its tables. And each user app will request to get this variable and compare it with the last one each time he start the application.

  • if equal => no change => continue with old SQLite database.
  • if grater => update SQLite database.

Or another way is to use GCM: 'Google Cloud Messaging" to send a message to all user telling them to download and sync the database, but this way needs a new database table on server side (MySQL database) to store user's id and their GCM Token.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.