title: How do i connect mysql database and insert data into it using android code
body: <p>I have <code>mysql database</code> on my hosting server </p>
  
  <p>On <code>simple android application</code> I have <code>feedback form</code> and on <code>submit</code> I want to <code>insert data into mysql database</code> which is on server .</p>
  
  <p>I <code>tried google</code> and found this following <code>solution for local machine</code></p>
  
  <blockquote>
    <p>how do I connect to my hosting server and mysql database without any php code?</p>
  </blockquote>
  
  <pre><code>public void insert()
      {
          ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
  
      nameValuePairs.add(new BasicNameValuePair("id",id));
      nameValuePairs.add(new BasicNameValuePair("name",name));
  
          try
          {
          HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("http://10.0.2.2/insert.php");
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              HttpResponse response = httpclient.execute(httppost); 
              HttpEntity entity = response.getEntity();
              is = entity.getContent();
              Log.e("pass 1", "connection success ");
      }
          catch(Exception e)
      {
              Log.e("Fail 1", e.toString());
              Toast.makeText(getApplicationContext(), "Invalid IP Address",
              Toast.LENGTH_LONG).show();
      }     
  
          try
          {
              BufferedReader reader = new BufferedReader
              (new InputStreamReader(is,"iso-8859-1"),8);
              StringBuilder sb = new StringBuilder();
              while ((line = reader.readLine()) != null)
          {
                  sb.append(line + "\n");
              }
              is.close();
              result = sb.toString();
          Log.e("pass 2", "connection success ");
      }
          catch(Exception e)
      {
              Log.e("Fail 2", e.toString());
      }     
  
      try
      {
              JSONObject json_data = new JSONObject(result);
              code=(json_data.getInt("code"));
  
              if(code==1)
              {
          Toast.makeText(getBaseContext(), "Inserted Successfully",
              Toast.LENGTH_SHORT).show();
              }
              else
              {
           Toast.makeText(getBaseContext(), "Sorry, Try Again",
              Toast.LENGTH_LONG).show();
              }
      }
      catch(Exception e)
      {
              Log.e("Fail 3", e.toString());
      }
      }
  </code></pre>