Ryan.ye
Ryan.ye

Reputation: 39

sqlite blob read and write

I want to store a long string into sqlite of android. I write it into sqlite by:

String content = bodytext.toString();
    byte[] contentByte = content.getBytes();
    Log.d("bytetoString",new String(contentByte));
    String sql1 = "insert into content(id,content) values( '" + messageID
            + "','" + contentByte + "');";
    db.execSQL(sql1); 

and I read it by:

String sql = "select * from content where id='" + messageID + "'";
    Cursor temp = db.rawQuery(sql, null);
    if (temp.moveToNext()) {
        byte[] contentByte = temp.getBlob(temp.getColumnIndex("content"));
        String sb = new String(contentByte);
        Log.d("String",sb);
        temp.close();
        return sb;
    }

However, when I print the string which I just read. it prints out something like " [B@41431930?? " is there something wrong?

Upvotes: 2

Views: 4237

Answers (1)

kosa
kosa

Reputation: 66637

It is an array and toString() prints just memory address. That is why you are seeing [B@41431930??

If you want readable values use something like java.util.Arrays.toString(contentByte)

Upvotes: 3

Related Questions