
if(!cur.moveToFirst()){
//没有数据
}
我是这么做的,在hellokitty的表里找hello数据,如果!cur.moveToFirst 就表明没有数据。。否则就存在数据
sqlite判断表是否存在,代码如下:
/*** 判断某张表是否存在
* @param tabName 表名
* @return
*/
public boolean tabIsExist(String tabName){
boolean result = false
if(tabName == null){
return false
}
SQLiteDatabase db = null
Cursor cursor = null
try {
db = this.getReadableDatabase()//此this是继承SQLiteOpenHelper类得到的
String sql = select count(*) as c from sqlite_master where type ='table' and name ='+tabName.trim()+'
cursor = db.rawQuery(sql, null)
if(cursor.moveToNext()){
int count = cursor.getInt(0)
if(count>0){
result = true
}
}
} catch (Exception e) {
// TODO: handle exception
}
return result
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)