MySQL连接android,android连接mysql(android connect mysql)

im trying to connect mysql in android app. Below is my code. Once i run the code i get 'Error parsing data org.json.JSONException: End of input at character 0 of' error. I was using this tutorial

code

public class Test extends Activity{

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//setContentView(R.layout.mainabout);

String result = "";

//the year data to send

ArrayList nameValuePairs = new ArrayList();

nameValuePairs.add(new BasicNameValuePair("year","1980"));

InputStream is = null;

//http post

try{

HttpClient httpclient = new DefaultHttpClient();

HttpGet httppost = new HttpGet("http://www.pherma.net84.net/admin/getAllPeopleBornAfter.php");

// httppost.s//setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);

HttpEntity entity = response.getEntity();

is = entity.getContent();

}catch(Exception e){

Log.e("log_tag", "Error in http connection "+e.toString());

}

//convert response to string

try{

BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);

StringBuilder sb = new StringBuilder();

String line = null;

while ((line = reader.readLine()) != null) {

sb.append(line + "\n");

}

is.close();

result=sb.toString();

}

catch(Exception e){

Log.e("log_tag", "Error converting result "+e.toString());

}

try

{

JSONArray jArray = new JSONArray(result);

for(int i=0;i

JSONObject json_data = jArray.getJSONObject(i);

Log.i("log_tag","id: "+json_data.getInt("id")+

", name: "+json_data.getString("name")+

", sex: "+json_data.getInt("sex")+

", birthyear: "+json_data.getInt("birthyear")

);

}

}

catch(JSONException e){

Log.e("log_tag", "Error parsing data "+e.toString());

}

}

}

logcat

3e2f2e58ede68b034bd5d12c08218dbe.png

php

mysql_connect(".com","a4055820_root","");

mysql_select_db("a4055820_pherma");

$q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'");

while($e=mysql_fetch_assoc($q))

$output[]=$e;

print(json_encode($output));

mysql_close();

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值