我正在尝试连接Android,PHP和MySql。 为此,使用Android作为前端我试图将数据插入MySql Db。 我已经使用logcat输出将信息显示为适当的位置。 响应将在logcat中显示,但MySql中没有数据。 请帮帮我!!
这是我的代码:
public JSONObject getJsonData(String url_create_product, List<NameValuePair> parameters)
{
try
{
Log.e("url is:"," "+url_create_product.toString());
DefaultHttpClient httpClient= new DefaultHttpClient();
Log.e("httpClient is:"," "+httpClient.toString());
HttpPost httpPost=new HttpPost(url_create_product);
Log.e("httpPost is:"," "+httpPost.toString());
httpPost.setEntity(new UrlEncodedFormEntity(parameters));
Log.e("encoded parameters are: "," "+parameters.toString());
try
{
httpResponse=httpClient.execute(httpPost);
Log.e("httpResponse is:"," "+httpResponse.toString());
}
catch (Exception e)
{
e.printStackTrace();
}
int statusCode=httpResponse.getStatusLine().getStatusCode();
if (statusCode==200)
{
Log.e("statusCode is:","200");
HttpEntity httpEntity=httpResponse.getEntity();
inputStream=httpEntity.getContent();
Log.e("inputStream is:"," "+inputStream.toString());
BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
inputStream.close();
json = sb.toString();
Log.e("json is:"," "+json.toString());
jsonObject=new JSONObject(json);
Log.e("jsonObject is:"," "+jsonObject.toString());
}
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonObject;
}