dongshen2903 2015-02-19 14:59
浏览 37

通过PHP将List发送到android中的MYSQL

I built an android application, the application contain SQLite DB, i need when the user open the application a service run in background to compare the values in local SQlite with the data in MYSQL (Hosted externally), the comparision will based on status value, so the i took the ID and Status from the local SQlite and compare it with cloud data, if the Status value in cloud more than the status in local it mean that the data was changed so the application will update the local data. Now i am wrote below code to get the ID and Status from local SQLite:

private void get_local_cloud_compare() {
          data= new DataHandler(this);
             data.open();
             Cursor bcreturneddata = data.returndata();
             if(bcreturneddata.moveToFirst())
                {
                    do
                    {
        IDslist.add(bcreturneddata.getString(0));// 0 position for ID
        Statuslist.add(bcreturneddata.getString(8));// 8'th position for status
                    }while(bcreturneddata.moveToNext());

                    }

             data.close();
    }

now usually when i need to communicate with MYSQL database i used the below code:

private void checkchanges(// argument here ) {


     InputStream isr = null;
    String result = null;
    try
    {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new  HttpPost("here the url of my php file");   
httppost.setEntity(new UrlEncodedFormEntity(here ArrayList<NameValuePair>));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
}
catch (Exception e)
{
e.printStackTrace();
}
try 
{
BufferedReader reader = new BufferedReader(new InputStreamReader(isr,"iso-8859-1"),8);                  
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) !=null)
{
sb.append(line +"
");
}
isr.close();
result = sb.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
JSONArray jarray = new JSONArray(result);
for ( int i =0; i<jarray.length();i++)
{
JSONObject json = jarray.getJSONObject(i);
//here i read the new received data
}
}
catch (Exception e)
{
e.printStackTrace();
}
}

Now in this line: httppost.setEntity(new UrlEncodedFormEntity(here ArrayList)); how i can pass the two lists IDslist and statuslist instead on namevaluepair ?

and how will be the code of PHP file that will take the IDs list and download data to compare it locally, i just need to know how to download the data from MYSQL based on IDslist instead of namevaluepair since there is no exact number of rows in local DB ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?