android如何检查数据库表是否为空?

android如何检查数据库表是否为空?,android,Android,我想要以下概念的代码 如果Data\u Base\u Table为空,则将数据插入Data\u Base\u Table。这只是一次。如果Data\u Base\u Table中的数据已经存在,则表示什么都不做。我这样写 这里我正在检查数据库表数据是否为空,是否正确 公共布尔checkDataBaseTable(){ SQLiteDatabase=this.getReadableDatabase() 我用这样的方式: Cursor cursor = db.query(your-table-nam

我想要以下概念的代码 如果Data\u Base\u Table为空,则将数据插入Data\u Base\u Table。这只是一次。如果Data\u Base\u Table中的数据已经存在,则表示什么都不做。我这样写 这里我正在检查数据库表数据是否为空,是否正确 公共布尔checkDataBaseTable(){ SQLiteDatabase=this.getReadableDatabase()


我用这样的方式:

Cursor cursor = db.query(your-table-name, columns, null, null, null);
if(cursor.getCount() > 0) {
    //do some stuff when there is data in the table
} else {
   //do some stuff when there is no data
}
请尝试使用此代码

Cursor cursor = database.query(TABLE_NAME, null, null, null, null, null,null);
if(cursor.getCount()>0)
{
     // database not empty
} else {
    // database empty
}

在tab表上写一个查询get count如果(cursor!=null&&cursor.getCount()>0){//以防您的游标为null。检查它是否不等于null}否则{}你好,Jigar Shekh,每次调用数据库not empty时,即使在卸载和安装后,也会调用数据库not empty。请回复me@Thej,您的数据库存储在sdcard中?嗨,Jigar,谢谢您的回复。我的问题解决了。我没有明白您的意思。
Cursor cursor = database.query(TABLE_NAME, null, null, null, null, null,null);
if(cursor.getCount()>0)
{
     // database not empty
} else {
    // database empty
}