JDS
JDS

Reputation: 16978

How to have Android app work with MySQL online database?

So I have an android app where users will be entering text and what not, and I want to store (and later retrieve) this info from an online database. Currently I have a LAMP server set up online that I can use.

How do I go about doing this? I really don't know how to interface java with PHP and MySQL to make this stuff possible. Are there alternate solutions I can look into?

Thanks.

Upvotes: 0

Views: 2589

Answers (2)

smbell
smbell

Reputation: 46

On your LAMP server you should be writing a web service API for your android application to talk to. Depending on what data you are sending/reading you'll have alot of security concerns to deal with. I won't go into all that here.

Once your server side is setup you can connect to your site using the DefaultHttpClient class. Something like this:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://url.to.my.app.com");
HttpResponse response = httpClient.execute(httpGet);
// handle response

An alternative to running (and writing) your own web service would be to connect to something like a google apps backend. You still have some writing to do but much of the security concerns are easier to handle.

Upvotes: 1

Marc B
Marc B

Reputation: 360672

You'd need to find an MySQL client library that works for Android, or implement one yourself from scratch within your app, so that you could connect to MySQL's TCP socket and deal with the DB directly.

However, exposing MySQL to the 'net directly in such a fashion is highly highly risky. I strongly advise you to write a PHP middle-ware layer to act as a gatekeeper, otherwise your DB is likely to get cracked into and sucked dry.

Upvotes: 4

Related Questions