最近数据库用的比较多,所以就记录一下,以备未来使用
废话不多说,直接上代码
public static boolean HaveData(SQLiteDatabase db,String tablename){
Cursor cursor;
boolean a=false;
cursor = db.rawQuery("select name from sqlite_master where type='table' ", null);
while(cursor.moveToNext()){
//遍历出表名
String name = cursor.getString(0);
if(name.equals(tablename))
{
a=true;
}
Log.i("System.out", name);
}
if(a)
{
cursor=db.query(tablename,null,null,null,null,null,null);
//检查是不是空表
if(cursor.getCount()>0)
return true;
else
return false;
}
else
return false;
}