Lucas Arrefelt
Lucas Arrefelt

Reputation: 3929

Android fetch data from database

I've decided to try out some DB connections for my android applikation. However I need some advice regarding structure.

I came to know that in order to fetch data from DB with Android I need to use php scripts. I'm a total novice in this area and for me it sounds a bit akward. Therefore I figured I could create a Java server which the application connects to, and among other things this server also fetches data from the DB and returns.

In a performance perspective, what's best? Let the application itself fetch data from the DB, or connect to the server which fetches it for you? How about security? For clearance, I will have a Java server anyhow to take care of other things.

enter image description here

Sorry about the Vista paint skills. Thanks for any input!

Upvotes: 1

Views: 529

Answers (2)

Jeremy Edwards
Jeremy Edwards

Reputation: 14740

Like others have said it doesn't matter which you use PHP vs Java. But you're on the right track. Most developers create a web service on their HTTP Server and the app talks to that. That's usually in the form of JSON or XML strings over HTTP. Popular choice is using the REST architecture which essentially tells you that stuff you access on the service are resources and you structure your service based on that.

For the PHP vs Java question it's really up to you so do which ever you can setup faster and are more familiar with. I will also say Java has productivity advantages in Android's case because you can create plain old java objects as your models for results and share that code between the server and your Android client. You get this because you can use something like Gson library which serializes and deserializes objects into JSON format. You can also use Google AppEngine for hosting your Java code too.

Upvotes: 3

Anurag Ramdasan
Anurag Ramdasan

Reputation: 4330

Well this problem is irrelevant in context to android programming i would say.

Assuming that You are returning the extracted data to your device in json format, the entire performance issue is sort of restricted to the performance of java or php in retrieving data from database and converting it to json and sending to the client.

And as far as simple operations are considered the efficiency wont matter much in both cases, it is just a matter of preference on the developers part.

Upvotes: 1

Related Questions