I am making an android app which will retrieve some information from a remote MySQL database. I will be using restful java web service using JAX-RS which will interact with MySQL DB to retrieve data from tables. I am aware that for interacting with an underlying database, some implementation of JPA can be used. But since I only need to retrieve data from DB and not to insert any new data using my android app (as a client).
So do I really need to implement JPA?
If not, how should I make my java web service fetch data from MySQL database?
My database is installed on Amazon ec2-instance where I am running apache tomcat 7. What will be the best approach? If you can refer me to some good tutorials, please do.
You don’t need to implement JPA for this solution if it’s a fairly small set of data you require from your description. You could just build a RESTful web service that just does simple JDBC queries to the database whenever it’s called.
REST request comes in – gets interrogated by the web service – web service fetches data – returns XML / JSON response from Tomcat. Also – as you’re using Tomcat and not an application server, if you did want to go down the JPA route I would recommend Hibernate as you wouldn’t be able to use EJB without an application server such as JBoss. Even then, unless it was a large system just a Tomcat instance running some JDBC should work fine, especially in EC2.