All we need is a simple explanation of the problem, which is provided below.
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.
Let’s Solve it:
This is a common error many developers questioned us about it. So we write the explanation above. You just have to apply the suggested solution to your code and it will do for you. If you still getting this error after applying this code then comment below we will get back to you with the new method.
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 :-
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.
You need to have a web hosting to store a script online. You can write this script in e.g. 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
Note: You are free to use these solutions for your personal use. We recommend you apply the first solution to your code because it was tested in our system before posting it on this page.
We are always trying to help the developer community, So we made their work easy. Basically, we collected these data from stackoverflow.com, As it is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0.