将Android连接到MySQL

So I'm really new to this. I was following a tutorial on web that showed how to connect these two. But everything I do it just jumps to catch part and it says "No connection". What am I missing? I also connect to a http server to use a PHP script which queries username and password from the database.

try
    {
        nameValuePairs = new ArrayList<NameValuePair>();

        nameValuePairs.add(new BasicNameValuePair("username", username));
        nameValuePairs.add(new BasicNameValuePair("password", password));

        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        response = httpClient.execute(httpPost);

        if(response.getStatusLine().getStatusCode()==200)
        {
            entity = response.getEntity();

            if(entity != null)
            {
                InputStream instream = entity.getContent();

                JSONObject jsonResponse = new JSONObject(instream.toString());

                String retUser = jsonResponse.getString("upime");
                String retPass = jsonResponse.getString("geslo");

                if(username.equals(retUser) && password.equals(retPass))
                {
                    SharedPreferences sp = getSharedPreferences("logindetails", 0);

                    SharedPreferences.Editor spedit = sp.edit();

                    spedit.putString("upime", username);
                    spedit.putString("geslo", password);

                    spedit.commit();

                    Toast.makeText(getBaseContext(), "Login successful", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    Toast.makeText(getBaseContext(), "Failed to login", Toast.LENGTH_SHORT).show();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getBaseContext(), "No connection", Toast.LENGTH_LONG).show();
    }
 <?php 
 header('Content-Type: application/json'); 
 $dbhost ="localhost"; 
 $dbuser = "username"; 
 $dbpass = "password"; 
 $dbdb = "db"; 
 $connect = mysql_connect($db_host, $dbuser, $dbpass) or die("connection error"); 

 mysql_select_db($dbdb);
 $username =$_POST['username'];
 $password=$_POST['password'];
 $query = mysql_query("SELECT * FROM users WHERE user='$username' AND pass='$password'");

  $num = mysql_num_rows($query);
 if($num == 1) 
{ 
 while($list=mysql_fetch_assoc($query))
 { $output = $list; 
 }
  mysql_close(); 


 echo json_encode($output);


?>

edit the final "echou" to echo and add

    header('Content-Type: application/json'); 

You have to create webservice in which php code is written. web service can be soap and Rest. and you have to write url of webservice in http client object.

By doing this you can connect android and mysql.

HttpPost postD=new HttpPost("url");

Have you given Internet Permission in your android manifest?

 <uses-permission android:name="android.permission.INTERNET" />