我想将记录从数据库发送到服务器,然后将其删除。这是我在服务中发送和删除的代码。
DBAdapter db=new DBAdapter(this);
db.open();
Cursor cursor=db.getAllData();
if(cursor.moveToFirst())
{
do{
jObject = new JSONObject();
jObject.put("Imei", cursor.getString(1));
jObject.put("Lat", cursor.getString(2));
jObject.put("Long", cursor.getString(3));
jObject.put("Gpsdatetime", cursor.getString(4));
jObject.put("Speed", cursor.getString(5));
jObject.put("Altitude",cursor.getString(6));
jObject.put("Battery", cursor.getString(7));
//jArray.put(jObject);
String datatoServer = jObject.toString()+"\n";
Toast.makeText(getApplicationContext(),datatoServer, Toast.LENGTH_LONG).show();
HttpEntity entity;
HttpClient client = new DefaultHttpClient();
String url = "http://url";
HttpPost request = new HttpPost(url);
StringEntity se = new StringEntity(datatoServer);
se.setContentEncoding("UTF-8");
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
"application/json"));
entity = se;
request.setEntity(entity);
HttpResponse response = client.execute(request);
entity = response.getEntity();
db.deleteContacts(1);
}while(cursor.moveToNext());
}//if
db.close();
我对删除功能感到困惑。数据已正确发送到服务器,但仅删除第一行。
这是我的 DBHelper 类中的删除函数。它以 rowid 作为参数。
public boolean deleteContacts(long rowId)
{
return db.delete(DATABASE_TABLE, KEY_ROWID+"="+rowId, null)>0;
}