Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i'm beginner in android so i m made a android apps to connect sql server so plzzz help me and send me full coding of connecting of sql server nd android application
Posted
Updated 2-Mar-15 2:32am
v2
Comments
Richard MacCutchan 2-Mar-15 7:31am    
Sorry, this site does not provide code to order, you will need to write it for yourself.
Matej Hlatky 2-Mar-15 14:11pm    
http://lmgtfy.com/?q=connect+to+sql+server+android

1 solution

Following steps
1. Create your own mysql database
2. Write your web service in PHP or .NET
Sample code
PHP
<?php
$host = '198.57.182.115';
$user = 'root';
$password = 'root';
$dbName = "db";

$link = mysql_connect($host, $user, $password);
mysql_select_db($dbName, $link);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo "Connect successfully";
?>


3. Write your android code to call the web service to get the data
Java
String responseBody = null;
     HttpClient httpclient = HttpsClient
             .getHttpsClient(new DefaultHttpClient());
     HttpPost httppost = new HttpPost("Link to your web sevice");
     try {
        // Execute HTTP Post Request
         ResponseHandler<String> responseHandler = new BasicResponseHandler();
         responseBody = httpclient.execute(httppost, responseHandler);
         Log.d("responseBody: ", responseBody);
     } catch (UnsupportedEncodingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         return e.toString();
     } catch (ClientProtocolException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         return e.toString();
     } catch (JSONException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         return e.toString();
     } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
         return e.toString();
     }

In above code, responseBody is the return data from webservice
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900