前端之家收集整理的这篇文章主要介绍了
SQLite数据库判断表是否存在的方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
public boolean tableIsExist(String tableName){
boolean result = false;
if(tableName == null){
return false;
}
sqliteDatabase db = null;
Cursor cursor = null;
try {
db = this.getReadableDatabase();
String sql = "SELECT COUNT(*) as c FROM sqlite_master where type ='table' and name ='"+ tableName.trim()+"' ";
cursor = db.rawQuery(sql,null);
if(cursor.moveToNext()){
int count = cursor.getInt(0);
if(count>0){
result = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
原文链接:https://www.f2er.com/sqlite/199293.html