我正在尝试使用 BLOB 将一些图像上传到 SQLite 数据库。尽管根据文档应将 blob 长度限制为 2GB,但即使图像大小为 100 KB,也会引发 android.database.sqlite.SQLiteBlobTooBigException。 我怎样才能避免这种情况?
这是我的代码:
public ArrayList<Group> getGruppi(){
ArrayList<Group> returnList = new ArrayList<>();
String queryString = "SELECT * FROM GRUPPI";
SQLiteDatabase db = this.getReadableDatabase(); //readable
Cursor cursor = db.rawQuery(queryString, null);
if (cursor.moveToFirst()) {
//if there are results
do {
int gId = cursor.getInt(0); //i get the index THIS INDEX IS BOUND TO THE OBJECT
String gNome = cursor.getString(1);
//bypasso l' indice 2
String gDesc = cursor.getString(3);
String gImgPath = cursor.getString(4);
byte[] imageBlob = cursor.getBlob(5);
Group gruppo;
gruppo = new Group(gNome);
if (gDesc != null) gruppo.setDescription(gDesc);
if (gImgPath != null) gruppo.setImagePath(gImgPath);
if (imageBlob != null) gruppo.setImageBlob(imageBlob);
returnList.add(gruppo);
} while (cursor.moveToNext()); //CASTS EXCEPTION
}
cursor.close();
db.close();
return returnList;
}
我知道这样做不是一个好习惯,但是我用作模拟器的手机的存储不是标准的 storage/0/emulated,所以我无法将图像的路径存储在数据库中。< /p>