7

I want to connect a MySql DB with my android application.
However, I DON'T want to/CAN'T use PHP for doing this.

Almost all solution for MySql connection with android on internet uses PHP.
I read somewhere that, If one don't want to use PHP then web service should be used.

But I'm not able to find any tutorial/sample example for the same.

Any help appreciated.

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
GAMA
  • 5,958
  • 14
  • 79
  • 126

4 Answers4

3

It seems you're mixing up some things.

A web service is simply some code on the internet (web) which allows you to receive and send information to a server, where it is saved per example in a database.

PHP is just a language, in which you can write a web service.

You can use a vast array of languages to create a web service ( read: expose your database) to other devices. Among others, you can easily do this in Java, .NET, Python ...

If you're looking for a way to connect to an external database without any web service / API in between, i'll have to disappoint you with the news that this is not supported by Android.

Most examples of a simple web service / a bunch of scripts contain PHP since this is probably the easiest and can be used on pretty much any server.

Stefan de Bruijn
  • 6,289
  • 2
  • 23
  • 31
  • but PHP requires wampserver na? – GAMA Jan 03 '13 at 10:17
  • so if I don't want to use **PHP** at all, I should write a web service in `Java` to connect to `MySql`? Will it require anything else (any external server or tool)? – GAMA Jan 03 '13 at 10:19
2

A webservice, is as it's called, a service, meaning that you have one side consuming it (the android client). if all you want is a persistent storage, you could use SQLite which is an SQL compliant solution which exists within android.

If it's possible to SSH to a server via Android, you could use that to connect to mysql, because the only other solution involves having mysql binaries installed locally on your android machine, and that's not possible AS FAR AS I KNOW, on Android.

Itai Sagi
  • 5,537
  • 12
  • 49
  • 73
1

One major reason for using a webservice (e.g. written in PHP) to connect to a remote DB is that you don't want to store the database login credentials inside your app. Because otherwise it'll be easy to extract your login for that database and access and edit it in a way you might not have planned (eg. delete stuff).

florian h
  • 1,162
  • 1
  • 10
  • 24
  • can that web service be written in Java also? – GAMA Jan 03 '13 at 10:26
  • That would absolutely be possible, yes. It would just receive the requests from your app (in what form ever), should check if they are valid/legal and submit a MySQL query. I think most tutorials just mention PHP because that's most popular with MySQL – but you could use whatever language you want for your webserver. – florian h Jan 03 '13 at 10:35
  • Did this answer your question or are there still any obscurities? – florian h Jan 05 '13 at 14:27
  • m constantly facing connection difficulties while connecting mysql to android... it's giving Incorrect syntax,privileges,etc. exceptions – GAMA Jan 07 '13 at 06:40
  • Did you see this question (and the answer of Kurian)? Because if you really dont want to use a webserver JDBC seems the way to go: http://stackoverflow.com/questions/4447692/jdbc-connection-in-android – florian h Jan 07 '13 at 11:29
-1

Its Possible to connect mysql database .

I have done with out using php file . I have used an spring configuration file to establish an connection to the database and dao to access the data from the database.

Create an Web Application that access the Server through the Spring Framework and an Servlet .

Create an Android Client Application tat make an get / post request to the Servlet , process the results in the servlet and return the response to the Android Client Application (json format ) Process the json format reponse in the Android Client Side and use it to your application

Manjunath
  • 123
  • 1
  • 1
  • 4