Marco,

   I haven't gotten all the bugs out yet but I was looking for a
similar suggestion.  I use php on the server side to manipulate the
MySQL database and then I'm trying to bring back the response to my
Android application.  See the code below:


public class SelectLocation extends Activity {
    /** Called when the activity is first created. */
    String result = "";
    String jnow = "";

        private Reader in;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                BufferedReader in = null;
                try {
                        HttpClient client = new DefaultHttpClient();
                        HttpGet request = new HttpGet();
                        request.setURI(new URI("http://www.mysite.com/
grabitgood.php"));
                        HttpResponse response = client.execute(request);
                        in = new BufferedReader (new
InputStreamReader(response.getEntity().getContent()));
                        StringBuffer sb = new StringBuffer("");
                        String line = "";
                        String NL = System.getProperty("line.separator");
                        while ((line = in.readLine()) != null) {
                                sb.append(line + NL);
                        }
                        in.close();
                        String result = sb.toString();
                        String jnow = result.substring(result.indexOf("["),
result.length()-1);
                        int herenow = (result.lastIndexOf("["));
                        System.out.println(jnow);

                        } catch (URISyntaxException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } catch (ClientProtocolException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } finally {
                                if (in != null) {
                                        try {
                                                in.close();
                                        } catch (IOException e) {
                                                e.printStackTrace();
                                        }
                                }
                        }

        //parse json data
        try{
                JSONArray jArray = new JSONArray(jnow);
                for(int i=0;i<jArray.length();i++){
                        JSONObject json_data =
jArray.getJSONObject(i);
                        Log.i("log_tag","org_id:
"+json_data.getInt("id")+
                                ", orgname:
"+json_data.getString("orgname")+
                                ", cityname:
"+json_data.getString("cityname")+
                                ", statename:
"+json_data.getString("statename")
                        );
                }
        }catch(JSONException e){
                Log.e("log_tag", "Error parsing data "+e.toString());
        }
    }
    public void BufferedReader(Reader in) {
        this.in = in;
    }
}

If you can resolve JSON exception problem you are there. And if you do
please let me know.

Thanks,
Capt Spaghetti

On Oct 19, 4:24 am, marco pierobon <mav...@gmail.com> wrote:
> Hi, I have to develop a program that need to access a MySQL database
> to retrieve information stored there. I searched through the Web but I
> cannot find any definitive best approach to get it done: someone
> advices SOAP, someone else HTTPClient or XMLRPC.
> Can I get some advices by some of you guys more savvy Android
> developer than me?
> Thank you for your attention
> Marco Pierobon

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to