Solved

Getting Android to access a simple MySQL database

Posted on 2013-01-18
8
602 Views
Last Modified: 2013-02-08
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.
0
Comment
Question by:cidlockie
8 Comments
 
LVL 16

Expert Comment

by:Chris Harte
ID: 38793100
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.
0
 

Author Comment

by:cidlockie
ID: 38793352
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.
0
 
LVL 16

Expert Comment

by:Valeri
ID: 38793780
0
 

Author Comment

by:cidlockie
ID: 38793879
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:Chris Harte
ID: 38796475
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.
0
 
LVL 15

Accepted Solution

by:
Ess Kay earned 500 total points
ID: 38807543
0
 

Author Comment

by:cidlockie
ID: 38843397
Apologies, this is still ongoing, I just haven't had time to try it out again yet.
0
 

Author Closing Comment

by:cidlockie
ID: 38867700
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.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now