Get DB-Data from Server - android

I have a problem with my application. I need the data from my MySQL-Database on the server. Usally I'm using HTTP-Posts, but this time I'm have to get a lot of db-Entrys. So I thought, that i'm just copying the database to the device. But here is the next problem: The Database on the device has the same structure like the db on the server, and additional 2 extra tables, to save some local data.
Finally my question is, how to get a lot of data from my database?
One extra question: is it possible/effective to use 2 local databases? So i could use 1 for local data and the other one for the server data. Then it would be possible to copy the db, but i need also an mysql-query, because i don't want to copy the whole data.

Yes, is possible to have 2 local db, and the best way to download an entire db from server is to dump the mysql db on server to a sqlite db, and so you may download the sqlite db from your mobile app.

Well choosing a database is depends on your project requirement. If your data is getting updated frequently on server and you want the display the updated data to the user. Do not copy database in mobile. Instead of it use webservices to get data from remote server.
And Yea, you can create two database in Android, nothing wrong in it. But again I would suggest that for only two tables do not create separate database.That can be merged in single database.
Summary
Frequently Updates in Data : Use MySql + Webservice
Static Data : Go for local db

Related

Transferring data from Sql server to SQLITE with Android

I have software that connects to an SQL database. I am now working on the software on Android, using SQLite, and need to transfer the SQL database (with the data) to SQLite.
How can I do this?
One way would be to create the SQLite database on the device and download and persist the data into the local SQLite data base. A good place to read up on how to do this is in the Android docs.
Another possible solution would be to create the SQLite database at the server level and download it directly within the Android app then open it. But if you modify anything locally within the app you would need to send data back to the server to keep in sync.
Create Rest API that will fetch my SQL data in JSON format.
Now from android app access that API to get data and insert that data in in your SQLite.
or if you want to fetch it in background process use sync Adapter.

Syncing local device SQLite to my mySQL server

I have an Android app on the play store which uses a local SQLite DB on the device.
However, in a planned update, I want to sync the SQLite DB with an external MySQL server with the same table and database structure, through a PHP webservice.
However, in this case, I not only want to make sure the changes in my SQLite DB are reflected in my MySQL DB, I also want to make sure that the changes in my MySQL DB get reflected in the SQLite.
Would appriciate any suggestions about how to go about it.
When you call method of web service for update external MySQL server, this method can return result of this update to Android client.
please refer this link and check first two tutorial . it may solve your problem

android sqlite update online with updating the app and affecting user inputted data

I using SQLite as my database.
Using the app, the user can save some item on the database.
But I would like also to update the database from time to time.
The problem is how can I update the database without affecting the user inserted data and in a manner that it will download the new database online and not by updating the app itself.
Since my comment is large, I'll post it as an answer.
You won't find any tutorial showing exactly what you're trying to accomplish, because what you need is somewhat complex (but not difficult)
First approach:
You need your app to query some webservice to find out if there's a newer version of the database, and if there is, download it
The database must be saved in some temporary location, then you transfer all the users saved data to the new database, and finally replace the apps database with the new database (already updated with user's data)
Another approach would be:
Make your app query some webservice to find if the database needs to be updated.
If yes, download the SQL commands to modify the database structure.

Sending SQLite db to web service

I have an android app which populates a SQLite database with numerous latitudes and longitudes. I then need that data to be stored in an external SQL Server db. The problem I'm having is sending that file to a web service. I cannot find any examples on how the class should look that takes in the db file and stores it in a separate SQL Server db. Is this even the way I should be approaching my problem?
A better approach would be to send the actual lat/long data to db via a web service rather than sending the entire db file itself.
Doing it in this way would accomplish several things:
It should be much simpler to implement
You would not need to support SQLite on the server side, just the client
The data "set up" would be immediately available for querying - rather than needing to be extracted from the SQLite db file before it can be used
EDIT: How frequently and how much you upload is entirely up to you. You can make it user-activated or on some time interval and upload the latest data in bulk fashion or one-at-a-time until you're up to date. In either case you would track which data needs to be uploaded with a timestamp.
One simple method for transfering "in bulk" would be to pull the data that you need to save from you SQLite db and put it into a JSON or XML object which would be interpreted on the server as a collection of lat/long data. This would put the whole upload into a single web service call rather than having to loop through your "newest" records and calling a web service for each item.
Rather than sending a database to server you should have a mechanism that can export only data and send it to the database.
You can export the data into the CSV file or any other format and then you can send it to the sever so that server can easily read that CSV and insert that data into the database.
Also you can read your SQLite database and then you can make a structured data like XML, JSON.
then you can connect to the webservice and then send thay structured file to the server.
CSV is the best option if you have much data and you want to send it to the server.

Getting remote database data into local database in android

We want to get the remote database data into local database first and then we want to access the local database. Can you please suggest us how to approach for this with sample code. Our remote database is MSSQL Server.
Have the app query the remote server, return the data from MSSQL to android code via JSON, insert into SQLite.
Edit: type MySQL to MSSQL
Get desired data from mysql ...in the form of xml from server. Parse that xml in android and fill desired java beans inside collection. then write state of object's in collection to sqlite dataabase.
I would suggest next time providing some code that indicates at least that you attempted to connect to your database first, and then if you run into trouble, someone here may be able to help. As opposed to just asking for sample code.
If you're talking about replication, I'm not sure this is possible from SQL Server to SQLite, otherwise, the answer to your question is simple, you would connect to your SQL Server database probably through some sort of exposed API, retrieve the data, parse it, and update your local SQLite Database accordingly.
Here's a link to a tutorial that covers connecting to local databases: NotePad Tutorial

Categories

Resources