A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 诺忔。初禾、 高级黑马   /  2014-5-10 23:18  /  1272 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

sqlitedatabase怎么判断存不存在数据库表。新手求教

3 个回复

倒序浏览
没人知道么
回复 使用道具 举报
?????????
回复 使用道具 举报

/**
         * 判断某张表是否存在
         * @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();
                        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;
        }
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马