如何将sqlite表的值与android中的json标记值进行比较
我想将如何将sqlite表的值与android中的json标记值进行比较,android,json,sqlite,Android,Json,Sqlite,我想将sqlite中的id值与来自json Web服务的TAG\u id值进行比较。我只是坚持这样做 到目前为止,我所尝试的是 class LoadAll extends AsyncTask<String, String, String> { protected String doInBackground(String... args) { Log.i("url ",url_all_prod
sqlite
中的id值与来自json Web服务的TAG\u id
值进行比较。我只是坚持这样做
到目前为止,我所尝试的是
class LoadAll extends AsyncTask<String, String, String>
{
protected String doInBackground(String... args)
{
Log.i("url ",url_all_products);
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET",params);
Log.w("All book: ", json.toString());
Log.i(url_all_products, url_all_products);
try
{
System.err.println("json array "+json.getJSONArray(TAG_PRODUCTS));
bookProduct = json.getJSONArray(TAG_PRODUCTS);
}
catch (JSONException e)
{
e.printStackTrace();
}
if(data_exist!=bookProduct.length()){
Log.i("in update","m here");
Cursor cursors = getRawEvents("select id from bcuk_book");
try{
for (int i = 0; i < bookProduct.length(); i++) {
JSONObject c = bookProduct.getJSONObject(i);
String Bid = c.getString(TAG_ID);
ArrayList<String> mapId = new ArrayList<String>();
mapId.add(TAG_ID);
Log.e(Bid,Bid);
while(cursors.moveToNext())
{
System.err.println("update coded STEON"+cursors.getString(0));
Log.e(Bid,c.getString(TAG_ID));
}
}
}
catch(JSONException e){
e.printStackTrace();
}
}
else{
Log.i("Done good","m here");
}
return null;
}
此语句是变量data_exist=cursor.getCount()代码>
而bookProduct.length
是jsonarray的长度,我想比较一下,如果长度不一样,那么我想将新值更新到sqlite中。有人能建议我这样做的方法吗
如果长度不相同,则我希望将新值更新为
sqlite
不是更新数据库的好方法。
假设服务器数据库字段中有一些更改。计数相同,但内容不同。
我就是这样做的:
String sql = "select * from " + DB_TABLE + " where " + TAG_ID + "='" + id + "'";
Cursor c = database.rawQuery(sql, null);
c.moveToFirst();
if( c.getCount() > 0){ // already in the database
// update entry with TAG_ID = id
}
else{ // new entry
// add new entry
}
如果长度不相同,则我希望将新值更新为
sqlite
不是更新数据库的好方法。
假设服务器数据库字段中有一些更改。计数相同,但内容不同。
我就是这样做的:
String sql = "select * from " + DB_TABLE + " where " + TAG_ID + "='" + id + "'";
Cursor c = database.rawQuery(sql, null);
c.moveToFirst();
if( c.getCount() > 0){ // already in the database
// update entry with TAG_ID = id
}
else{ // new entry
// add new entry
}