How to connect Sql Server Database from android app?

What are the best ways to connect an Android app to a MySQL database ?

  • I want to access an online MySQL database in order to retrieve and manipulate data.

  • Answer:

    Create a RESTful service that accesses the database and returns what the calling application wants. You will need an intermediate Web-Application server to do that. Then you can call the service from your Android App. You can also reuse it in future if you need to call it from an iPhone App or another web application. You can also directly connect to a MySQL Database from your Android app using a JDBC driver specific to android. But it is not recommended. If you still want to do it here is a sample code http://capdroid.wordpress.com/2012/07/10/configuring-and-accessing-mysql-jdbc-driver-on-android-application/

Vijay Kamath at Quora Visit the source

Was this solution helpful to you?

Other answers

Connecting application direct to DB is insecure, you should have middleware between db and app

Matt Rutkowski

Hello ...I here mention below some links for connect database to Android App..http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ Links...Make a class to make an HTTP request to the server. For example (I am using JSON parsing to get the values): public class JSONfunctions { public static JSONObject getJSONfromURL(String url) { InputStream is = null; String result = ""; JSONObject jArray = null; // Download JSON data from URL try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } // Convert response to string try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result " + e.toString()); } try { jArray = new JSONObject(result); } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } return jArray; } } In your MainActivity, make an object with the class JsonFunctions and pass the URL from where you want to get the data as an argument. For example: JSONObject jsonobject; jsonobject = JSONfunctions.getJSONfromURL("http://YOUR_DATABASE_URL"); And then finally read the JSON tags and store the values in an ArrayList. Later, show them in a ListView if you want.

Archan Desai

using any server side programming languages such as php,jsp.if you want to access mySQL database you will need to create a web services in any server side programming language and call those web services from android app.

Prashant Jondhale

Best way to connect your Android App to MySQL Database isCreate Middle level communication layer with PHP or Any other technology ( webservice) and you can call that webservice with your app.Simple solution - you can easily find script from other developer communities like herehttps://stackoverflow.com/questions/6806015/android-mysql-connectionHope it might worksthanks

T Vyas

I believe that for these kinds of development, you can create an API to do the job. Unless, you need something else done? Did I get the question right? haha

Eugene Maning

Creating a Rest api or service is inbuilt the way to do it. Android in it supports sqlite and for mysql db connection u have to create apis to interact ....

Kartikey Shrivastava

we will need to connect Mysql database to an android app: First of all you should have a an online server where you can make your database. You can also use local host for this purpose Php Script that will run on server and fetch the data from MySql database And last but not least you will have an android app to display data from Mysql database after making proper connection. For more information visit : http://www.trustingeeks.com/connect-android-app-to-mysql-database/

William Peter

You can connect the app with DB. Follow this link ->>http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

Pratikesh Gowdra

A direct connection between android and MySql is not possible (as far as I know). To read/write data between android app and MySql DB you should have a web app the connects to MySql and provide the android app with an API to deal with the DB.

Anas Rabei

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.