External Database and Android application - android

I am creating an android application which records soccer scores.
I have an external mysql database created on my own host.
How do i retrieve the data from the database in order to display it in my application?
Thanks in advance!

You need to write a service hosted on your database using either php or some other language you are comfortable which exposes data as XML/JSON.
Android has HTTPURLConnection capability,using which you can query your service by passing the parameters. Your service queries database and consturcts data either as XML or JSON using libraries and returns to app.
Your app need to parse the response (if XML, using SAX/DOM or someother APIs, if JSON using Android in-buit json parser) and display. Here is an example on how to do.

If you also want to retrive the information to be used offline, you can create an empty database locally, and update it by passing SQL statements. This is not the most efficient way to do it, but it worked for me since I am not working with a huge db.
Otherwise, use HTTP connection connecting to your remote host and pass the result via JSON object.

Related

how to make an android app that downloads dynamic forms from mysql database and uploading them the record after filling them?

im making an android-based data collection app similar to ODKcollect as a college project and im not that good so..
1-how to make a web service and connect my app to mysql database and which language is better for a web-service (PS:my data maycontain images)
2-how to make dynamic form templates then retrieving them from database and making them in the android app.
You can use php for that, You can write a php script that retrieve values from Mysql Database and then decode them to JSON and parse them to the android app. and another script to make the vice-versa Take a JSON response from your app and insert it into the Database.
There was a course in udemy that achieves such pattern you might want to check it

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.

Updating a SQL database on an Android app with data from an SQL database on a server

I need some help, my app created a database on creation at the minute.
What I want is to get the information in a database on a server or PC and load it into my app.
It just needs to be from server to app, not back again.
I have no idea how I would do this, does anyone have any ideas?
first, I should say that your question is so wide. It contains alot of technologies.
So, I'll give you a breif walk through here. you should figure out the rest on your own. and then, you can come back and ask more specific questions.
That said, here is the path you should take:
On the server, implement a REST API that respond to the caller with the data in the server database.
example: http://your.server.com/api/somedata
calling this url with GET method should return the data you want in JSON format.
from your android application, call this url and save the response in a String.
parse the JSON String ( you can use gson ).
save the parsed data to your local database.
If you are the one developing the server api, then this book is a recommended reading:
RESTful Web Services
Update
Say you have a table in your server database called (TABLE) with the columns COL_1, COL_2, COL_3.
You could implement a php page called 'TABLE.php' that return the following:
{
"items": [
{"COL_1": "value_1", "COL_2": "value_2", "COL_3": "value_3"},
{"COL_1": "value_2", "COL_2": "value_3", "COL_3": "value_4"},
{"COL_1": "value_4", "COL_2": "value_5", "COL_3": "value_6"},
...
]
}
In your android application call http://your.server.com/api/TABLE.php page with GET method, parse the JSON returned (above) and save it to your local database.
You can do this for each database table on your server, until you have all your data saved locally in your android application.
This probably wont be the best design decision, but considering your knowledge about the topics, this could be a fair starting point.
Using HttpClient you can set things up to execute a POST to some servlet or similar app on the server. That app needs to then send data back to your Android app which is waiting for a response from the server. Then your app can parse the data and stuff it's own database.

If i have a DB on the server, what is the best approach to query for data from my android app?

Im new to android development. I realized if DB were to be on the phone updating it would be tedious. So though keeping DB on the server is better of but retrieving data from DB to App is what im having doubts with.
You cannot connect directly to the DB, you will need a web service to do so. Look at the http.client to help you get started on this.
SQLite would be the best choice depending on what you're creating your application for.
The approach you may need to choose will be, have a service hosted on your server (could be written in any programming language) which retrieves/posts data from database and sends data in either JSON/XML format ( I did JSon format) to app. In your app use HTTPClient to get/post data to service hosted on your server. Parse the data using Android in built JSon API.

Send data from Android app to web service

I have an Android application with a SQLite database from which I want to send some data to a webservice to store it in a database there.
How would I go about doing this? Is there a smart way of doing it?
I've thought about just extracting the data from the SQLite database and create an XML file to hold and then send the XML file to the webservice, but is there a easier/better way of doing this?
JSON is generally seen as a more efficient data format for transferring to and from mobile devices. Check out this post about how to do it. You will, of course, need a web service that can accept and interpret JSON objects.

Categories

Resources