![](/img/trans.png)
[英]Error java.sql.SQLException: not implemented by SQLite JDBC driver when Retrieving Blob (Image) from Database
[英]Retrieving image from SQLite Database (BLOB data type)
我嘗試使用以下代碼從我的 SQLite DB 中檢索 byte[]:
public byte[] getImageData() throws SQLException{
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT AVATAR_IMAGE FROM AVATAR_TABLE WHERE AVATAR_ID = 1", null);
cursor.moveToFirst();
byte[] blob = cursor.getBlob(1);
return blob;
}
返回錯誤:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:241292 flg=0x1 }} to activity {com.example.physicalactivity/com.example.physicalactivity.ProfileActivity}: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
您的查詢:
SELECT AVATAR_IMAGE FROM AVATAR_TABLE WHERE AVATAR_ID = 1
僅返回 1 列,並且由於 cursor 中的列索引基於0
,因此您應該使用以下命令檢索它:
byte[] blob = cursor.getBlob(0);
此外,您應該使用moveToFirst()
檢查 cursor 在檢索列值之前是否返回任何行:
byte[] blob = null;
if (cursor.moveToFirst()) blob = cursor.getBlob(0);
return blob;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.