1

我想根据行位置从我的数据库中检索一个 blob

我正在使用游标从 SQLite 数据库中检索数据

 public Cursor getTestData(int index,String house) 
 { 
     try 
     { 
         String sql ="SELECT * FROM Heroes where position ="+ index +" and house='"+house+"'";             
         Cursor mCur = mDb.rawQuery(sql, null); 
         if (mCur!=null) 
         { 
            mCur.moveToFirst(); 
         } 
         return mCur; 
     } 
     catch (SQLException mSQLException)  
     { 
         Log.e(TAG, "getTestData >>"+ mSQLException.toString()); 
         throw mSQLException; 
     } 
 }

这将返回所有列,我可以通过以下方式轻松获取字符串

Cursor testdata = mDbHelper.getTestData(pos,house); 
String sName = Utility.GetColumnValue(testdata, "name");
String sAdvance = Utility.GetColumnValue(testdata, "class");

这将返回我的列“名称”和“类”值,但如何检索 blob 并显示它。

Byte[] img = Utility.GetImage(testdata, "image1");

这就是我尝试的方式

public static byte[] GetImage(Cursor cur,String ColumnName){
    return cur.getBlob(cur.getColumnIndex(ColumnName));
}

但在 img 中为 null :(

4

0 回答 0