Android sqlite中判断某个表是不是存在方法
展开全部
sqlite 中判断某个表是否存在的方法
/**
* 判断某张表是否存在
* @param tabName 表名
* @return
*/
public boolean tabbleIsExist(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) {
// TODO: handle exception
}
return result;
}
/**
* 判断某张表是否存在
* @param tabName 表名
* @return
*/
public boolean tabbleIsExist(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) {
// TODO: handle exception
}
return result;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |