• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

connection from mysql to android emulator

nagaraja

Lurker
[FONT=&quot]{ String result = [/FONT][FONT=&quot]""[/FONT][FONT=&quot];[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot]//the year data to send[/FONT][FONT=&quot][/FONT]
[FONT=&quot] ArrayList<NameValuePair> nameValuePairs = [/FONT][FONT=&quot]new[/FONT][FONT=&quot] ArrayList<NameValuePair>();[/FONT][FONT=&quot][/FONT]
[FONT=&quot] nameValuePairs.add([/FONT][FONT=&quot]new[/FONT][FONT=&quot] BasicNameValuePair([/FONT][FONT=&quot]""[/FONT][FONT=&quot],[/FONT][FONT=&quot]"1980"[/FONT][FONT=&quot]));[/FONT][FONT=&quot][/FONT]
[FONT=&quot] HttpClient httpclient = [/FONT][FONT=&quot]new[/FONT][FONT=&quot] DefaultHttpClient();[/FONT][FONT=&quot][/FONT]
[FONT=&quot] HttpPost httppost = [/FONT][FONT=&quot]new[/FONT][FONT=&quot] HttpPost([/FONT][FONT=&quot]"http://localhost/getAllPeopleBornAfter.php"[/FONT][FONT=&quot]);[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot]try[/FONT][FONT=&quot][/FONT]
[FONT=&quot] {[/FONT][FONT=&quot][/FONT]
[FONT=&quot] httppost.setEntity([/FONT][FONT=&quot]new[/FONT][FONT=&quot] UrlEncodedFormEntity(nameValuePairs));[/FONT][FONT=&quot][/FONT]
[FONT=&quot] HttpResponse response = httpclient.execute(httppost);[/FONT][FONT=&quot][/FONT]
[FONT=&quot] HttpEntity entity = response.getEntity();[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot]//convert response to string[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot][/FONT]
[FONT=&quot] InputStream is = response.getEntity().getContent(); [/FONT][FONT=&quot][/FONT]
[FONT=&quot] BufferedInputStream bis = [/FONT][FONT=&quot]new[/FONT][FONT=&quot] BufferedInputStream(is);[/FONT][FONT=&quot][/FONT]
[FONT=&quot] StringBuilder sb = [/FONT][FONT=&quot]new[/FONT][FONT=&quot] StringBuilder();[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot]int[/FONT][FONT=&quot] line = 0;[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot]while[/FONT][FONT=&quot] ((line = bis.read()) != 0)[/FONT][FONT=&quot][/FONT]
[FONT=&quot] {[/FONT][FONT=&quot][/FONT]
[FONT=&quot] sb.append(line + [/FONT][FONT=&quot]"n"[/FONT][FONT=&quot]);[/FONT][FONT=&quot][/FONT]
[FONT=&quot] }[/FONT][FONT=&quot][/FONT]
[FONT=&quot] is.close();[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot][/FONT]
[FONT=&quot] result=sb.toString();[/FONT][FONT=&quot][/FONT]
[FONT=&quot] }[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT][FONT=&quot]catch[/FONT][FONT=&quot](Exception e)[/FONT][FONT=&quot][/FONT]
[FONT=&quot] {[/FONT][FONT=&quot][/FONT]
[FONT=&quot] Log.e([/FONT][FONT=&quot]"log_tag"[/FONT][FONT=&quot], [/FONT][FONT=&quot]"Error converting result "[/FONT][FONT=&quot]+e.toString());[/FONT][FONT=&quot][/FONT]
[FONT=&quot] }[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT]
 
Back
Top Bottom