Link to home
Start Free TrialLog in
Avatar of cidlockie
cidlockieFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Getting Android to access a simple MySQL database

I have a MySQL database sitting behind a website that I own. What I want to do is create an Android app (for personal use only) which works as follows:

1. One screen with two buttons, A and B. No special graphics.
2. If you press button A, it accesses a table called 'countries' in the database and shows a screen of all columns in that table, of the rows where the 'country_initial' column contains an A.
3. If you press button B, it accesses the table called 'countries' and shows a screen of all columns in that table, of the rows where the 'country_initial' column contains a B.

I have full access to the database. The only table in the database I'm interested here is 'countries'.

I have been trying to work out how to do this (I know the basics of Java and have been fiddling about with the Android SDK but don't seem to be getting anywhere). It seems like a very simple thing to do, so if anyone can help me out (or point me to a tutorial that would help me with this) I'd be very grateful.

The simpler I can make it the better as I intend to learn how to do more complicated stuff from this example. Thanks.
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

I think you are coming from the wrong direction. Android apps are for accessing databases that are on the phone, usually SQLite. To access a database behind a website I would suggest you write a login page for mobiles then access it through the web browser on your phone.

Because the database you are using sounds very small, the best solution is to write your own app, since you also wish to learn how to code android.

This is a very good tutorial. Start at 1 and work your way through

http://thenewboston.org/list.php?cat=6

Databases are not addressed until video 111 but they are on average 5 mins long so you should be through the whole lot in a couple of days. You can even skip the ones about graphics and stuff you will not be using.
Avatar of cidlockie

ASKER

Thanks for that link, it does look useful for a number of things.

I get what you mean about the phone wanting to deal with a local SQLite database rather than a remote MySQL one. However, it seems a little pointless creating a web page that I then access through the browser of the phone, as the website itself can be accessed directly via the phone's browser.

It seems implausible that there's not some way to get small amounts of data out of a MySQL database to populate a simple Android application, even if there needs to be some SQLite step halfway between the two.
Based on the comments at the bottom of the link I suspect it's probably not what I need (I'm no expert as I said), but I'll give it a go tomorrow, thanks.
This does what you want. (I think, I have not tried it, I am just assuming it works).

http://androiddevelopement.blogspot.co.uk/2011/09/connecting-to-remote-mysql-database.html

It also makes the point that you cannot connect directly to a remote server, you have to use a webservice and pass the data as a JSON object, via a php script. All other options seem to involve SOAP or setting up xml feeds.
ASKER CERTIFIED SOLUTION
Avatar of Ess Kay
Ess Kay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Apologies, this is still ongoing, I just haven't had time to try it out again yet.
I think the second link in the accepted answer is going to prove closest to what I need here. Thanks to everyone for your replies.