user591124
user591124

Reputation: 505

Android application connect to local server SQL

I need to store data on a SQL on the localserver(for now) from an Android application. I wanted to know how this can be done? I have read about "having to use a web service like php for the job" and "google app engine" but have not yet clearly understood the whole process/concept. It would be amazing if anyone out there could provide me start to end tutorials on developing a simple app mentioned below.

An app which has a text input box and when the user enters the message and clicks send the message should be stored in the local server database. Another button called listener which will take the message from the database and show it on the screen.

If you give me guidelines on how to develop the app above it wud be really great.

Upvotes: 0

Views: 1622

Answers (3)

Eric
Eric

Reputation: 1973

You definitely want a middle layer out there between the internet and your mySql database. It would be very foolish to allow something from the internet to directly connect into your DB, even if on a limited user.

My suggestion:

  • Create a very limited user with absolute least priveledges possible.
  • Create a few php pages you can hit with a HttpClient in android, POST to them your username/pw for the limited user acct. You can be even more cautious with security here if you want.
  • Each php page will execute a predefined sql using the supplied username/pw and possibly a parameter (if so, research how to guard against SQL injection!) and return the result in json which is easily parsed in android. (See JSONObject in android)
  • Simply httppost to those url's when you need the data.

This is also pretty close to RESTful web implementation, which is nice in it's own right and will make life easier down the road ;)

Upvotes: 1

Kenny
Kenny

Reputation: 5542

If you want the database to be on the handset use SQLite, take a look at the link, it covers setting up a SQLite database then importing it into your project:

http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

Once you have the database helper up and running you can create your own methods to insert/extract/edit data to/from the tables withing the db, this link cover the syntax of the queries:

http://www.firstsql.com/tutor.htm

Hope this helps, it might not quite be what you want!

Upvotes: 0

piotrpo
piotrpo

Reputation: 12636

Having database port exposed in internet is stupid idea because:

  • Security reasons
  • Data amount passed over network
  • Implementation problems due to lack of support for JDBC in Android API.

In your case you should write web service (JSON i.e.) in one of your favorite language. Service is barely saying internet application without any pages. This service should expose method like this:

public void storeName(String name);

In android client you call service and pass to them parameter entered by app user. Service when called just inserts parameter into database.

Upvotes: 3

Related Questions