读取指定路径数据库的方法

 private SQLiteDatabase geSql;
    /**
     * quertLoccalStorageData
     * */
    public synchronized JSONObject queryLocalStorageData()
    {
        byte[] blob_value;
        JSONObject loccalStorageJO = new JSONObject();
        String _value;
        File dbpath = new File("数据库的路径");
        try
        {
            geSql =  SQLiteDatabase.openOrCreateDatabase(dbpath,null);
        }
        catch (Exception e)
        {
            geSql = null;
        }
        if(geSql==null){
            return null;
        }
        Cursor cursor = geSql.query("数据库表明",null,null,null,null,null,null,null);
        if(cursor.moveToFirst())
        {
            do
            {
                String _id = cursor.getString(0);//取出表里所有的key
                blob_value = cursor.getBlob(1);//取出表里所有的value 设置数据类型
                int index=0;
                byte[] array = new byte[blob_value.length/2];
                for (int i = 0; i < blob_value.length; i = i + 2) {
                    array[index++] = blob_value[i];
                }
//                try {
//                    _value = new String(array,"UTF-8");
//                    loccalStorageJO.put(_id,_value);
//                } catch (UnsupportedEncodingException e)
//                {
//                    e.printStackTrace();
//                }catch (JSONException e)
//                {
//                    e.printStackTrace();
//                }
            }while (cursor.moveToNext());
        }
        cursor.close();
        return loccalStorageJO;
    }

猜你喜欢

转载自blog.csdn.net/u011479990/article/details/79470496