Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(need advice) Talk to MySQL server database from my Android App

I am starting my thesis which is an app for android. This app is based on a web platform I had created.

The part where I need advice is: which is the most efficient way to pull data from a MySQL server into the application. Please give me some advice and your experience on the matter.

(I've read about encoding the queries in json, but it seems like awful lot of needless work)

like image 367
MayTheSchwartzBeWithYou Avatar asked Aug 14 '12 15:08

MayTheSchwartzBeWithYou


People also ask

Can Android app connect to MySQL database?

Android does not support MySQL out of the box. The "normal" way to access your database would be to put a Restful server in front of it and use the HTTPS protocol to connect to the Restful front end.


1 Answers

I suggest you to use RESTful Web Service in Java using Jersey as an intermediate layer between you Android App and MySQL server. You can transfer data in JSON (my suggestion for a mobile app), xml or palin text to your Android App.

You can find the benefits of using Web Service in you system in @Elad answer : Best way to access a remote database: via webservice or direct DB-access?

Also later if you decide to develop other smart phone platform for your system, you just need to reuse the same Web Service. As a result this Web service can be considered as a generic protocol for the mobile user of your system.

I used Hibernate to map the data to MySQL database. RESTful Service Using Jersey with Hibernate Persistence

If you decide to follow this approach note that it is highly recommended to separate your hibernate stuff form your Jersey services. You need to wire your DAO to your Service tier. see what @Rick Mangi wrote to me : REST with Java (JAX-RS) using Jersey and hibernate

It is also good approach to use HTTP Client in your Android App, Since it supports @GET, @POST, @DELETE and @PUT commands and you can easily talk to your database like HTTP GET Request

like image 50
Ali Avatar answered Oct 02 '22 15:10

Ali