0

MAIN

please help me am try to store image as blob in sqlite but i got like string format i don't know what i am doing wrong..

public byte[] photo=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button insert=(Button)findViewById(R.id.insert);

    final SQLiteDatabase db;
    db=openOrCreateDatabase("demo", Context.MODE_PRIVATE, null);
    db.execSQL("create table if not exists demo1(Dp BLOB );");
    insert.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Bitmap b=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            //ContentValues cv=new ContentValues();
            ByteArrayOutputStream bos=new ByteArrayOutputStream();
            b.compress(Bitmap.CompressFormat.PNG, 90, bos);
            photo=bos.toByteArray();
            db.execSQL("INSERT INTO demo1(Dp)VALUES('"+photo+"')");
        }
    });
}
Rakesh
  • 37
  • 1
  • 7
  • _Image saving in data base like Dp="[B@40d0c7e8"_ – Rakesh Sep 30 '15 at 08:55
  • 1
    it is normal, consider [this](http://stackoverflow.com/questions/1536054/how-to-convert-byte-array-to-string-and-vice-versa) and also [this](http://stackoverflow.com/questions/88838/how-to-convert-strings-to-and-from-utf8-byte-arrays-in-java) – Oleh Dokuka Sep 30 '15 at 08:58
  • _so we can't save in normal database correct?_ – Rakesh Sep 30 '15 at 09:34
  • yep, sqlite db does not support feature like save image as it is, only primitive types like string – Oleh Dokuka Sep 30 '15 at 09:45

0 Answers0