本文介绍了Sqlite检查表是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,我有一个数据库,它有很多表。但一般表是空的。
我想检查数据库表是否为空。
如果表为空,程序将填充它。
public static long queryNumEntries(SQLiteDatabase db,String table)
我会使用它,但它需要API 11。
中执行 select count(*)并检查 count> 0
<$> c $ c> SQLiteDatabase db = table.getWritableDatabase();
String count =SELECT count(*)FROM table;
Cursor mcursor = db.rawQuery(count,null);
mcursor.moveToFirst();
int icount = mcursor.getInt(0);
if(icount> 0)
// leave
else
//填充表
Well, I have a databse and it has lots of table. but generally tables are empty.I want check if a database table is empty.IF table is empty, program will fill it.
public static long queryNumEntries (SQLiteDatabase db, String table)
I will use it but it requre API 11.
解决方案 you can execute select count(*) from table
and check if count> 0
then leave else populate it.
like
SQLiteDatabase db = table.getWritableDatabase();
String count = "SELECT count(*) FROM table";
Cursor mcursor = db.rawQuery(count, null);
mcursor.moveToFirst();
int icount = mcursor.getInt(0);
if(icount>0)
//leave
else
//populate table
这篇关于Sqlite检查表是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!