Android mysql connexion problem


Last Updated: 2012-02-28 18:55:41
  1. anddebutan

    anddebutan New Member

    Hello,

    I am trying to connect my android application with mysql database.
    This is my source code:

    php code:
    PHP:
    1. <?php
    2.   mysql_connect("localhost","root","");
    3.   mysql_select_db("bdville");
    4.   $sql=mysql_query("select * from tblville where Nom_ville like '".$_REQUEST['ville']."%'");
    5.   while($row=mysql_fetch_assoc($sql))
    6.   $output[]=$row;
    7.   print(json_encode($output));
    8. ?>
    classVilleActivity.java:
    Code (Text):
    1. package com.exemple.ville;
    2.  
    3. import java.io.BufferedReader;
    4. import java.io.InputStream;
    5. import java.io.InputStreamReader;
    6. import java.util.ArrayList;
    7.  
    8. import org.apache.http.HttpEntity;
    9. import org.apache.http.HttpResponse;
    10. import org.apache.http.NameValuePair;
    11. import org.apache.http.client.HttpClient;
    12. import org.apache.http.client.entity.UrlEncodedFormEntity;
    13. import org.apache.http.client.methods.HttpPost;
    14. import org.apache.http.impl.client.DefaultHttpClient;
    15. import org.apache.http.message.BasicNameValuePair;
    16. import org.json.JSONArray;
    17. import org.json.JSONException;
    18. import org.json.JSONObject;
    19.  
    20. import com.exemple.ville.R;
    21.  
    22. import android.app.Activity;
    23. import android.os.Bundle;
    24. import android.util.Log;
    25. import android.widget.LinearLayout;
    26. import android.widget.TextView;
    27.  
    28. public class VilleActivity extends Activity {
    29.     TextView txt;
    30.     @Override
    31.     public void onCreate(Bundle savedInstanceState) {
    32.         super.onCreate(savedInstanceState);
    33.         setContentView(R.layout.main);
    34.  
    35.         LinearLayout rootLayout = new LinearLayout(getApplicationContext());  
    36.         txt = new TextView(getApplicationContext());  
    37.         rootLayout.addView(txt);  
    38.         setContentView(rootLayout);  
    39.  
    40.         // D

    Advertisement

Share This Page