MayTheSchwartzBeWithYou
MayTheSchwartzBeWithYou

Reputation: 1177

(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)

Upvotes: 6

Views: 3449

Answers (2)

Ali
Ali

Reputation: 9994

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

Upvotes: 7

t0mm13b
t0mm13b

Reputation: 34592

Perhaps, by using a MySQL Java connector, and directly connect to the server over port 3306 using the Java's JDBC connector as a Jar library imported into your Android project, as shown here, and also this was blogged a good while ago

Upvotes: 3

Related Questions