Connecting to MySQL from Android with JDBC
You can't access a MySQL DB from Android natively. EDIT: Actually you may be able to use JDBC, but it is not recommended (or may not work?) ... see Android JDBC not working: ClassNotFoundException on driver
See
http://www.helloandroid.com/tutorials/connecting-mysql-database
http://www.basic4ppc.com/forum/basic4android-getting-started-tutorials/8339-connect-android-mysql-database-tutorial.html
Android cannot connect directly to the database server. Therefore we
need to create a simple web service that will pass the requests to the
database and will return the response.
http://codeoncloud.blogspot.com/2012/03/android-mysql-client.html
For most [good] users this might be fine. But imagine you get a hacker that gets a hold of your program. I've decompiled my own applications and its scary what I've seen. What if they get your username / password to your database and wreak havoc? Bad.
Using JDBC MySQL to connect database in Android?
Generally MySql is installed with security restrictions so it is possible to access to it only from localhost.
You need to execute a command similar to the following to permit access from other ip
GRANT ALL PRIVILEGES
ON database.*
TO 'youruser'@'%'
IDENTIFIED BY 'yourpassword';
Note that it is a bad practice to offer access to MySql from any IP because it opens the possibility to be hacked. So generally it is a good idea to place a server that intercept requests from your android application and directly call the database.
Note: check also if it is open the route between your application and the mysql server.
If you use 3G you are not using a local network and the IP of the MySql server is different from 192.168.1.xxx (that is the ip of a local network). It is also possible that outside of the local network the MySql Server is not visible. It depends from the configuration of your network.
You need to "open" your network exposing the port to access mysql and checking which is the ip of your local network as seen from internet. Otherwise you can access to the local network using a phone with wireless connection to your local network.
How to make android connect directly to mysql
Although it is not recommended for Android to connect with mysql directly, you can possibly do so. I actually found another stack overflow link that explains why it is not recommended (in first answer) and also gives answer of your original query (in second answer). Please have a look:
Can we connect remote MySQL database in Android using JDBC?
How to connect Android with MySQL using Mysql JDBC driver
Android by default does not support MySQL. It has an in-built database i.e SQLite.
If you are trying to access MySQL database remotely, you should expose interface to this database with any standard web service.
E.g you could create RESTful Web Service on Server Side which is written using Java/PHP etc. and MySQL Connector. (Which you have already done!)
And your Android App could talk to this service with the URL generated using this web service.
Again, this question has been repeated previously, so you can check those solutions.
Related Topics
How to Redirect My Log Output from Logcat to the Sd-Card on an Android Device
How to Escape Special Characters Like ' in SQLite in Android
How to Parse JSON String in Android
Failed to Load Map. Error Contacting Google Servers. This Is Probably an Authentication Issue
How to Get the First Name and Last Name from Android Contacts
Unknown Option 'Allow-Unrelated-Histories'
Difference Between .Getpath() VS Cursor in Getting the Real Path of a File from Uri in Android
Android Map V2 Zoom to Show All the Markers
Remove All Unused Resources from an Android Project
Android Fragments. Retaining an Asynctask During Screen Rotation or Configuration Change
Meaning of Top, Ascent, Baseline, Descent, Bottom, and Leading in Android's Fontmetrics
Android Location Providers - Gps or Network Provider
How to Enable Google Play App Signing
Android Asynctask for Long Running Operations
How to Maintain Fragment State When Added to the Back Stack
How to Disable Scrolling on a Viewpager
How to Draw an Overlay on a Surfaceview Used by Camera on Android