您的位置:首页 > 移动开发 > Android开发

Android sqlite中判断某个表是否存在

2015-12-11 12:56 495 查看
转至:http://www.myexception.cn/sql/619651.html

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
} finally {
<span style="white-space:pre">			</span>cursor.close();
<span style="white-space:pre">		</span>}
return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: