安卓读取外部db数据库数据以及判断存在某表名

来源:互联网 发布:网络摄像头安装方法 编辑:程序博客网 时间:2024/06/08 15:53
1.是获取数据库
2.根据数据可查判断是否存在某表名
3.存在就对该表进行增删改查
注:注意权限
/**
 * 获取数据库然后 * @param  * @return */
public static SQLiteDatabase openDB(String dbPath){
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(
dbPath(数据库地址), null);
}
/** * 判断某张表是否存在 * @param tabName 表名 * @return */public static boolean tabIsExist(SQLiteDatabase db,String tabName){    boolean result = false;    if(tabName == null){        return false;    }    Cursor cursor = null;    try {        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;}

                                             
0 0