无法从android中的sqlite清除表 [英] Can not clear table from sqlite in android
问题描述
我使用服务每5分钟更新一次服务器数据记录,我想清除表中的所有数据,然后从服务器更新新数据,所以我在更新表以清除数据之前使用此代码:
I am updating the server data talble at every 5 minutes using service and i want to clear the all the data in the table and then update the new data from server so i am using this code before updating the table to clear the data:
public boolean deleteServerData() {
SQLiteDatabase db = this.getWritableDatabase();
if (getServerDataCount() > 0) {
if (db.delete(TABLE_SERVER_CONTACTS, null, null) > 0)
return true;
else
return false;
} else
return true;
}
但是当在删除前计数表中的行时,它会给我任何数字,例如"13",而在删除后它给我零,但是当我看到表中的数据时,它仍然存在并且将更新后的数据附加到表中,因此表根本无法清除数据.
But when is count the rows in the table before deleting it gives me any number say "13" and after deleting it gives me zero but when i see at the table data it still there and updated data is appended in the table so table can not clearing data at all.
请建议我是否有解决方案,或者我在代码中犯了任何错误.
please suggest me if any solution is there or any mistake is done by me in the code.
推荐答案
尝试 execSQL :
db.execSQL("DELETE FROM "+ TABLE_SERVER_CONTACTS);
这篇关于无法从android中的sqlite清除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!