六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 40|回复: 0

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

[复制链接]

升级  11%

65

主题

65

主题

65

主题

举人

Rank: 3Rank: 3

积分
233
 楼主| 发表于 2013-1-26 15:53:54 | 显示全部楼层 |阅读模式
<div class="t_f">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;    }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表