doujing5435 2014-07-05 12:15
浏览 78

保存SQLite android数据库中只有一行的id

My android app is getting & writing data to the server and to the SQlite database.

I am fetching values for jobaddress.id = 1from server using a query (below). The values in SELECTstatement are displaying perfectly in the UI of android app however when I press "Save", instead of values from the server, I need to save the id 1 from the server in the local database without shwoing the id in the UI.

PHP sript (query only) for retrieving data from server:

$tsql = "SELECT     tbl_manufacturers.manufacturers_name, tbl_appliances_models.appliances_models_name, tbl_appliances.appliances_serial, tbl_appliances.appliances_id, jobaddress.id
        FROM        jobaddress INNER JOIN
                  tbl_appliances ON jobaddress.id = tbl_appliances.appliances_jobaddress_id LEFT OUTER JOIN
                  tbl_appliances_models INNER JOIN
                  tbl_manufacturers ON tbl_appliances_models.appliances_models_manufacturers_id = tbl_manufacturers.manufacturers_id ON 
                  tbl_appliances.appliances_models_id = tbl_appliances_models.appliances_models_id
        WHERE     (tbl_appliances.appliances_companies_id = 1) AND (jobaddress.id = 1)";

Showing data using JSON Parser:

public void getJobAddress() 
{
    String result = null;
    InputStream isr = null;
    try
    {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://datanetbeta.multi-trade.co.uk/tablet/getJobAddress.php");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    isr = entity.getContent();
    }
    catch(Exception e)
    {
        Log.e("Log_tag", "Error in hhtp connection " + e.toString());

    }

    //convert Response to string
    try
    {
         BufferedReader reader = new BufferedReader(new InputStreamReader(isr,"UTF-8"), 8);
         StringBuilder sb = new StringBuilder();
         String line = null;
         while((line = reader.readLine()) != null)
         {

             sb.append(line + "
");
         }

         isr.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 < jArray.length(); i++)
        {
            JSONObject json = jArray.getJSONObject(0);
             s = json.getString("address1");
             t = json.getString("address2");
             u = json.getString("postcode");
        }

        tvJbAddrs1.setText(s);
        if(t == null)
        {
            tvJbAddrs2.setText("");
        }
        else
        {
            tvJbAddrs2.setText(t);
        }

        tvJbPostcode.setText(u);


    }


catch (Exception e)

{
Log.e("log_tag", "Error Parsing Data " + e.toString()); 

}

} //getJobAddress() ends
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安装svn网络有问题怎么办
    • ¥15 Python爬取指定微博话题下的内容,保存为txt
    • ¥15 vue2登录调用后端接口如何实现
    • ¥65 永磁型步进电机PID算法
    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥15 latex怎么处理论文引理引用参考文献