android sqlite 判断表是否存在

来源:互联网 发布:淘宝图片发布行为规范 编辑:程序博客网 时间:2024/06/06 10:49
    //判断表是否存在    public static boolean isTableExist(SQLiteDatabase database,String tableName) {        boolean isTableExist=false;        String sql = "select count(*) as c from sqlite_master where type ='table' and name =?";        Cursor c=database.rawQuery(sql, new String[]{tableName});        if(c.moveToNext()){            int count = c.getInt(0);            if(count>0){               return true;            }        }        c.close();        return isTableExist;    }