1

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!

1
  • I think that in your post you are more comparing Java to Php. Commented May 19, 2012 at 16:24

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this reply! Is it better to just pass the class object to the server or vice verca, or serialize into JSON and pass that? Read somewhere that using JSON is more efficient due to small sizes, which suits mobile services. Do you have any tutorials or similar to share about the REST topic?
Android doesn't support anything like RMI so you can't just take POJO objects and send them to the server. You'll have to serialize them yourself for that. Gson is a great way to accomplish this and it will work on the server as well assuming that you chose a Java server. JSON is very good because of the smaller sizes, much better than the verbose XML and it's easily consumable in Javascript too. It standard for JavaScript Object Notation by the way. There's plenty of tutorials on how to accomplish this just search. I recommend Gson over the SDK org.json in Android because it's faster.
Thanks again! This will definately be my approach
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.