Connecting app to MySQL or use web services?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Connecting app to MySQL or use web services?

Postby Enki » Tue Feb 09, 2010 3:27 pm

Hello everyone,

I'm New to Android and Java, developing an application. Need some help.

There is a website and MySQL DB. Some users. I want the app to be able to access the DB and get and put info into it. So that the website and the app would share one DB. I was researching into JDBC. But someone told me it's better to use web services.
The app supposed to be constantly running on the background by default, and sometimes it's possible just to use it for a short time with limited functions (without GPS). So if someone have the full functionality, the app supposed to track the phone and right it to the DB (for functions like to find a friend or record a path on google maps and send it to a friend).
Enki
Freshman
Freshman
 
Posts: 7
Joined: Thu Jan 28, 2010 6:17 pm
Location: Manchester, NH, USA

Top

Postby jonw » Thu Feb 11, 2010 12:50 am

So that's very broadly what you want to do, what's the question? :)
User avatar
jonw
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Feb 10, 2010 9:00 pm
Location: London

Postby Enki » Thu Feb 11, 2010 3:42 pm

jonw wrote:So that's very broadly what you want to do, what's the question? :)


One programmer told me that i cannot connect Android App to a DB on a server directly, i need to use web services. Is that true?
Or should i store data into local SQlite on the Android and then sync it with the DB on the server?
Enki
Freshman
Freshman
 
Posts: 7
Joined: Thu Jan 28, 2010 6:17 pm
Location: Manchester, NH, USA

Postby jonw » Thu Feb 11, 2010 4:00 pm

One programmer told me that i cannot connect Android App to a DB on a server directly, i need to use web services. Is that true?

Aha. OK cool :) Is that true? I don't think so;
http://developer.android.com/reference/ ... mmary.html
Or you could hack together some other way of doing it handling the socket connections etc yourself, but that is painful and probably error-prone. Or you could use some language other than Java but that would be slow unless you're linking in C i guess, but that way is madness as:

Or should i store data into local SQlite on the Android and then sync it with the DB on the server?

That is sounding like a much better idea because;
a) local reads from filesystem not network all the time = faster, and works with no net connection
b) by creating a REST-ful web service you benefit from abstraction, I mean you can change "under the hood" how the SQL works in the web service without having to change the client code, push updates to phones etc etc.

There are many other benefits to this approach, and while it can be more work up-front, at least you can build it in your language of choice -- in fact there's frameworks out there you can use which do most of the hard work for you and benefit from community support, why reinvent the wheel? :)
User avatar
jonw
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Feb 10, 2010 9:00 pm
Location: London

Postby Enki » Fri Feb 12, 2010 4:31 pm

Thank you Jonw,

That is also what i was thinking, it is better to store all data locally and sync them once a day probably. After all some people may not have internet connection sometimes, or in some places.

Would you be so kind to point me into right direction to research on DB synchronization? As i stated before , i'm new into programming, i'm currently switching from web design, so i'm familiar with XHTML, CSS and some PHP, i guess i'll be able to understand it if i find some tutorials and samples.
Enki
Freshman
Freshman
 
Posts: 7
Joined: Thu Jan 28, 2010 6:17 pm
Location: Manchester, NH, USA

Postby jonw » Fri Feb 12, 2010 7:40 pm

No worries!

I can't really help with the 'droid side of all this, as I have yet to play with the SQLite capabilities of droid myself, but there's tutorials on here and it seems pretty straight-forward (famous last words).

Caveat: this is all my opinion, if any wants to chip in please do!

On the web side, I'm not sure of your experience level but if you got the basics of PHP I'd recommend moving on to one of the popular & good PHP frameworks -- IMO I'd check out CakePHP or Kohana (based on CodeIgniter) for starters. Typo3, Zend and Symphony have their supporters, but seem more heavyweight & require more programming experience. Beware, there are a lot of really really bad PHP frameworks & scripts out there, but I can vouch for the above... :)

By getting to grips with one of them, chances are you will be learning about REST at the same time, as they tend to work according to the general principles of REST (as opposed to sth like SOAP, which is slow, horrible to work with and more error-prone), and you'll begin to see how URLs are transformed into db queries... Just have a play around, build a little database-driven website or something using the framework, def. have a look at phpMyAdmin for managing MySQL db's, and all that should give you the ability to start piecing the rest together for your droid app. But do use a framework as that will help with the arcane arts of SQL query performance, security issues such as SQL injection & XSS/XSRF/etc.

The framework docu will also contain pointers for getting started understanding SQL which is knowledge you can re-use when you start building the droid side of your app. Then the app requests URLs from the site which contain the data you want to upload to the web from the app, like GPRS data. The data is stored on the web as much as poss, on the phone as little as poss, and then the app requests URLs of a different form to query the web db to get err stuff back.

It's a lot to learn, but hey that's half the fun ;)
User avatar
jonw
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Feb 10, 2010 9:00 pm
Location: London

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Exabot [Bot] and 3 guests