无法从数据库中获取数据?

When I run my application it always giving me "invalid ip", unable to get the data from the database. I am a newbie so i dont know much about android. I get this code from google

following is my snippet code, please help me out.

    public class EnterGeneralDetails extends Activity {

    InputStream is=null;
    String result=null;
    String line=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_general_details);

        try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://thecapitalcitychurch.16mb.com/new/CohortName.php");
            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 + "
");
            }

            is.close();
            result = sb.toString();
            Log.e("Pass 2", "connection success ");
        }
        catch(Exception e)
        {
            Log.e("Fail 2", e.toString());
        }

        try
        {
            JSONArray JA=new JSONArray(result);
            JSONObject json= null;
            final String[] str1 = new String[JA.length()];
            final String[] str2 = new String[JA.length()];

            for(int i=0;i<JA.length();i++)
            {
                json=JA.getJSONObject(i);
                str1[i] = json.getString("ID");
                str2[i]=json.getString("Cohort_Name");
            }

            final Spinner sp = (Spinner) findViewById(R.id.spinner22);
            List<String> list = new ArrayList<String>();

            for(int i=0;i<str2.length;i++)
            {
                list.add(str2[i]);
            }


            Collections.sort(list);

            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
                    (getApplicationContext(), android.R.layout.simple_spinner_item, list);
            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            sp.setAdapter(dataAdapter);

            sp.setOnItemSelectedListener(new OnItemSelectedListener()
            {
                public void onItemSelected(AdapterView<?> arg0, View arg1,int position, long id)
                {
                    // TODO Auto-generated method stub

                    String item=sp.getSelectedItem().toString();

                    Toast.makeText(getApplicationContext(), item,
                            Toast.LENGTH_LONG).show();

                    Log.e("Item",item);
                }

                public void onNothingSelected(AdapterView<?> arg0)
                {
                    // TODO Auto-generated method stub
                }
            });
        }
        catch(Exception e)
        {
            Log.e("Fail 3", e.toString());
        }
    }

}

PHP CODE

<?php
    $DB_USER='u868549735_rj';
    $DB_PASS='myself00';
    $DB_HOST='mysql.hostinger.in';
    $DB_NAME='u868549735_db';
    $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
    /* check connection */
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
    }       

    $mysqli->query("SET NAMES 'utf8'");
    $sql="SELECT ID, Cohort_Name FROM Cohorts";
    $result=$mysqli->query($sql);
    while($e=mysqli_fetch_array($result)){
    $output[]=$e;
    }   

    print(json_encode($output));
    $mysqli->close();   

    ?>

As far as I can see you've got a NetworkOnMainThreadException. This occurs when you try to execute any network operation on the main thread.

The exception that is thrown when an application attempts to perform a networking operation on its main thread.

This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged. See the document Designing for Responsiveness.

To resolve this, take a look at AsyncTask.

private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         int count = urls.length;
         long totalSize = 0;
         for (int i = 0; i < count; i++) {
             totalSize += Downloader.downloadFile(urls[i]);
             publishProgress((int) ((i / (float) count) * 100));
             // Escape early if cancel() is called
             if (isCancelled()) break;
         }
         return totalSize;
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         showDialog("Downloaded " + result + " bytes");
     }
 }

Once created, a task is executed very simply:

new DownloadFilesTask().execute(url1, url2, url3);

PS: Using Log.e("Fail 1", e.toString()); is considered bad practice. Use e.printStackTrace() instead.