Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...