`
zhouxiaoli521
  • 浏览: 552899 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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;
    }
 
分享到:
评论
3 楼 zhouxiaoli521 2014-05-16  
lgj452555712 写道
cursor 没有关闭,最好加上finally 后关上
finally {
   if(null != cursor && !cursor.isClosed()){
cursor.close() ;
   }
}

2 楼 lgj452555712 2014-05-09  
cursor 没有关闭,最好加上finally 后关上
finally {
   if(null != cursor && !cursor.isClosed()){
cursor.close() ;
   }
}
1 楼 king520 2012-05-22  
很好很强大!

相关推荐

Global site tag (gtag.js) - Google Analytics