0

What is the best way to have a SQL database that can both be accessed by an android device via java code and by a web app via php code?

In my mind I imagined a MySQL database somewhere on the cloud that is accessed in all the normal ways by the web app using mysqli_connect and then somehow the same database calls are made in Java inside the android app.

But after some research it appears this may not be the way to do it. What is the way to do this correctly?

EDIT: It was suggested my question was too broad. What I want then is a database of some basic financial information which is stored on the cloud which is then able to be accessed via a web app written in the LAMP stack and via an android app (with java code).

It is a really simple problem but I am not sure what the best practice for such a problem is in android (I come from a web dev background)

3
  • This question is too broad. There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. Commented Apr 13, 2015 at 13:33
  • That being said, the answer to your question is: Make a web service that handles the data storage. I will not elaborate. Commented Apr 13, 2015 at 13:33
  • @jurgemaister Thanks. I updated the question. Maybe that narrows it down some. Commented Apr 13, 2015 at 13:38

1 Answer 1

2

The standard way to access a database for mobile application is different than a normal web page/application.

Mobile devices should never run queries in the database; What you do is create a web service that does all the queries in the database and then sends back HTTP responses in xml, JSON format to the mobile device for consumption.

At the same time you can create a web client that interacts with the web service the same way your mobile app does. This way if you get erroneous data you can debug the web service without having to recompile the code in the mobile app.

Do a Google search for restful web service

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

5 Comments

Thank you for the help. I will investigate further =)
@ScarletMerlin Purely subjective, but what is your favorite way to build a restful web service? I hear good things about Java (Jersey) + Eclipse. Also what is a good place to deploy it? AWS?
Is all about your preferences. I used php and it works just fine. C# makes things really easy if you want to create one using windows server. All you need is a server and use whatever language you want.
@CamilStaps But you could in theory just use the JDBC class in Java and connect to a database direct from your Android Studio project correct?
@AcroR yes, you could.

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.