当我尝试从 SQlite 获取数据且字段大小超过 2 MB 时,它会抛出异常
"Couldn't read row 0, col 0 from Cursor Window. Make sure the Cursor is initialized correctly before accessing data from it.
"
如何将超过 2 Mb 的字段存储到 string 中?
我将多个 Base64 字符串作为长文本存储在 sqlite 中,它存储成功,但是当我从数据库中获取数据时,由于该字段包含超过 2400000 个字符,因此出现异常。
这是代码
public ArrayList<HashMap<String, String>> selectRecordFromDbList(String qry, String[] args, boolean status) {
ArrayList<HashMap<String, String>> arraylist = null;
try {
HashMap<String, String> mapRow;
Cursor cursor = sqLiteDatabase.rawQuery(qry, args);
if (cursor.moveToFirst()) {
arraylist = new ArrayList<>();
do {
mapRow = new HashMap<>();
for (int i = 0; i < cursor.getColumnCount(); i++) {
mapRow.put(cursor.getColumnName(i), cursor.getString(i));
}
arraylist.add(mapRow);
} while (cursor.moveToNext());
}
if (cursor != null && cursor.isClosed()) {
cursor.close();
}
} catch (Exception e) {
Log.e("SqliteAssetHelper:", e.getMessage());
arraylist = null;
}
return arraylist;
}
不建议在 SQLite 数据库中存储大型 BLOBS 或类似数据。您应该使用文件系统并仅存储对数据库中数据的引用。
参考这个answer https://stackoverflow.com/a/12709158/1681267
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)