Retrieve a byte array from a cursor, or null if a byte array could not be retrieved. - Android Database

Android examples for Database:Cursor Get

Description

Retrieve a byte array from a cursor, or null if a byte array could not be retrieved.

Demo Code


import java.util.ArrayList;
import java.util.Locale;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;

public class Main{
    /**/*from  ww w  .ja  v a  2  s. c  o m*/
     * Retrieve a byte array from a cursor, or null if a byte array could not be retrieved.
     *
     * @param cursor The cursor from which to retrieve the value. Must be at a valid position.
     * @param columnIndex The index of the column from which to retrieve the value.
     * @return The String value, or null.
     */
    public static byte[] safeGetByteArrayFromCursor(Cursor cursor,
            int columnIndex) {
        try {
            return cursor.getBlob(columnIndex);
        } catch (SQLiteException e) {
            e.printStackTrace();
            return null;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
}

Related Tutorials