如何从 Android 应用程序的 SQLite 数据库中读取 sqlite 文本-字段(不是字符串)
How to read a sqlite text - field (not string) from SQLite database from Android App
我有:
带有 table 和类型 "text"
的数据字段的 sqlite 数据库,其中包含大字符串。字符串的大小为:
select length(mapdata) from mapobjects
结果:
29386
94111
95558
127952
35593
我尝试按照以下方式在我的 android 应用程序中读取数据
c = chronica_connection_read.rawQuery(sql, null);
c.moveToFirst();
while (!c.isAfterLast()) {
String mapdata = c.getString(c.getColumnIndex("mapdata"));
我得到:
java.lang.OutOfMemoryError: Failed to allocate a 58792 byte allocation with 14504 free bytes and 14KB until OOM
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
我猜数据不是很大,这是真正的内存问题。我想我处理错了。
关于如何阅读文本字段的任何帮助。
您没有正确读取光标中的数据,陷入了无限循环
c = chronica_connection_read.rawQuery(sql, null);
if (c.moveToFirst()) {
do {
String mapdata = c.getString(c.getColumnIndex("mapdata"));
// continue your work with the retrieved string
} while (c.moveToNext());
}
您也可以考虑在作业完成后关闭光标
c.close();
我有:
带有 table 和类型 "text"
的数据字段的 sqlite 数据库,其中包含大字符串。字符串的大小为:
select length(mapdata) from mapobjects
结果:
29386
94111
95558
127952
35593
我尝试按照以下方式在我的 android 应用程序中读取数据
c = chronica_connection_read.rawQuery(sql, null);
c.moveToFirst();
while (!c.isAfterLast()) {
String mapdata = c.getString(c.getColumnIndex("mapdata"));
我得到:
java.lang.OutOfMemoryError: Failed to allocate a 58792 byte allocation with 14504 free bytes and 14KB until OOM
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
我猜数据不是很大,这是真正的内存问题。我想我处理错了。 关于如何阅读文本字段的任何帮助。
您没有正确读取光标中的数据,陷入了无限循环
c = chronica_connection_read.rawQuery(sql, null);
if (c.moveToFirst()) {
do {
String mapdata = c.getString(c.getColumnIndex("mapdata"));
// continue your work with the retrieved string
} while (c.moveToNext());
}
您也可以考虑在作业完成后关闭光标
c.close();