1

I've seen many tutorials referring to how to do this locally and the rest of the tutorials are so riddled with mistakes that I was unable to salvage them (none of them referred to doing this with Android).

I've seen tutorials for using local DBs with android (that looks pretty simple). I want to be able to read/write to a MySQL DB I have on a server from the app. Before anyone asks: the user will not be entering info in/have access to the data going to the server.

I'm also unsure of what Class.forName I'd be able to use; I know "com.mysql.jdbc.Driver" requires additional drivers (which seems like a bad choice considering I want to use this for android apps).

Any tutorials or advice that would help me accomplish this? Perhaps I'm simply failing to find good tutorials, but so far the tutorials have left me more confused than when I started.

Rhyono
  • 2,420
  • 1
  • 25
  • 41

2 Answers2

1

A preferable approach would be that your Android device make HTTP requests to a RESTful Service (or a SOAP-based if you prefer), and this Server-side component connect to your MySQL Database throw JDBC. The service would convert the data extrated from the DB into a format that your device understands (JSON, XML or a bare String)

This way, your device only worries about getting data and presenting it to the user and the RESTful Service manages Database Connections, Transactions, Data formatting an other heavy/expensive operations.

Carlos Gavidia-Calderon
  • 7,145
  • 9
  • 34
  • 59
1

You are failing to find good tutorials because with Android there are no native classes to interact with a MySQL Database (only SQLite). You need a RESTful service to serve up the data using JSON or XML. See this link for a good read on how you might go about doing this.

I recently had a similar requirement except I had to interact with a SQL Server 2008 database. My very naive implementation used ASP.NET MVC to return the JSON. They have recently released a very nice Web API to do just that, without out all of the MVC. See this and this and browse around asp.net for some good information.

Also more good links:

Creating a RESTful API with php

https://stackoverflow.com/questions/238125/best-framework-for-php-and-creation-of-restful-based-web-services

Another PHP restful service example

Whats that you ask? How do you now call these "RESTful" services from Android? Here is a great read.

Also this answer utilizes some of the code from the previous link.

Community
  • 1
  • 1
Jack
  • 9,156
  • 4
  • 50
  • 75
  • Before diving into those links: will this allow the app to write to the database as well? – Rhyono Mar 01 '12 at 04:08
  • Your Android application will make HTTP calls to your REST service, which will read and write to/from the database. – Jack Mar 01 '12 at 04:10
  • I think JSON is also nice option. [check this](http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/) – SkyWalker Mar 01 '12 at 04:44