简体   繁体   中英

Connecting to external database - Android application

I am writing an application for my third year project. The application will require interaction with an external mySQL database. The application will retrieve data from the database and display it to the user in a ListView.

I have a good idea of what sort of functionality the application is going to have. I also have spent a lot of time working with ListViews and the local SQLite database. I also did a bit of reserach into the HttpUrlConnection class.

I am just wondering would anyone be able to offer me a little bit more guidance as to how I might go about accessing this external database?

Will it involve me having to write a web service to handle the transactions? and if so what would that involve as I have not encountered web services in my course just yet.

Any advice would be much appreciated. Also my application is intended for use on ICS v4.0.4.

Thanks everyone!

Yes you have to create Web Service to interact with External Database (MySql in your case). Its very easy to create Web service in PHP as its having one function which convert your DB data to JSON and you can easily parse the JSON data and display that in Listview or accordingly your requirement.

Here are some useful link which will help you to get more details :-

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ - Best from All

http://www.coderzheaven.com/2011/04/08/android-phpmysql-connection/

http://blog.sptechnolab.com/2011/02/10/android/android-connecting-to-mysql-using-php/

Hope it helps.

I would recommend that your android application talks to a restful service (intermediary service that is talking to your database) that will return the database objects you require. so its not a direct connection to a database but its a good example on this type of connectivity.

Will it involve me having to write a web service to handle the transactions?

Yes, if the database is not on the device, you will have to access it with network requests, which will have to handled by something.

what would that involve?

That depends on a lot of things. You can write a web service in pretty much any language you want as long as the server hosting it supports it. You could you Python, Ruby, PHP, Perl, Java, or .NET (if you have the framework) to name a few. Handling the actual database requests would have to be done on the server, which would return data back to your app - probably as JSON.

This link is surely very helpful. Follow this link completely, but make sure you do the following changes to the httpd.config file of your WAMP server as stated by this link

You need to have a web hosting to store a script online. You can write this script in eg php to insert user data in the database. In your app use Volley to take care of the script. Once you get the user data, call the script and listen to the result:

  • This is the first time the user logged in
  • The user has already registered
  • An error has occurred

Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM