Database – How to Insert Data to Database from Android

androiddatabaseMySQL

I have to build an application where the requirement is that my clients will send data from their Android device and I have to save that data to a database.

I have done the part of coding that inserts data from Android emulator to my XAMPP database on localhost, now I have to implement the real thing.

How can I connect the devices where my application will be installed to the XAMPP database I have created so that the data they send can be inserted into it?

Best Answer

Presumably your android application sends a request to a web application. In this case it is localhost, but when you deploy it, localhost will be replaced by the name or IP of the server that has xampp installed. If only it were this simple. There are some other things to consider:

  • Firewall - Computer housing xampp must be accessible from the outside world, and windows firewall by default stands at the doorway. Do be sure to allow all the ports you require (default mysql port is 3306, and default http port is 80).
  • DNS - Would be nice to access this server with a name rather than an IP address. If a thousand people install your application and the IP changes, a thousand people will have to change the configuration in order to make it work. Better to give it a name.
  • Security - Not only does all this have to work, but it also must be secure. And no, windows firewall does not make it secure. Suppose you allowed just anyone to access your mysql database and hackers filled it up with trash (consequently filling up your disk). In your case, you may be accessing the database through Apache, but you still must ensure that a reasonable amount of protection exists.

For what concerns the firewall, you must know how to fix this since you must get it up and running. The last two are a job for a systems administrator, not you. You need to know only to know what problems may arise, but you should not have to also know everything there is to know about security (consider liability for a moment).

Most importantly, try it before you try to install it. By that I mean, buy an android phone, install your application, and configure it to point to your server and see if it works. I can guarantee there will be problems. The trick is to start with the assumption that there will be problems, and it will make your life easier.

Hope that helps!