1

What does 'howard.jpg' do in the sql statement below & how do I insert the image into my android app?

CREATE TABLE IF NOT EXISTS employee ( 
    _id INTEGER PRIMARY KEY AUTOINCREMENT, 
    firstName VARCHAR(50), 
    lastName VARCHAR(50), 
    title VARCHAR(50), 
    department VARCHAR(50), 
    managerId INTEGER, 
    city VARCHAR(50), 
    officePhone VARCHAR(30), 
    cellPhone VARCHAR(30),  
    email VARCHAR(30), 
    picture VARCHAR(200)) 



    INSERT INTO employee VALUES(1,'Ryan','Howard','Vice President, North East', 
'Management', NULL, 'Scranton','570-999-8888','570-999-8887','ryan@dundermifflin.com','howard.jpg')
Valentin Rocher
  • 11,667
  • 45
  • 59

3 Answers3

0

'howard.jpg' is just a string that is put into the varchar column. You should use BLOB instead of varchar for jpg and put not the name of a picture, but actual bytes of it. Refer here for more details.

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
0

To store an image file inside your sqlite db you should use a BLOB field and due android sqlite limitations you should store info in this way:

ContentValues cv = new ContentValues();
//your table fields goes here
...
// adding the bitmap in byte array way to the blob field
ByteArrayOutputStream out = new ByteArrayOutputStream();
friendInfo.getImage_bmp().compress(Bitmap.CompressFormat.PNG, 100,out);
cv.put("avatar_img", out.toByteArray());
db.insert(TABLE_NAME, null, cv);

and to read it you can do:

byte[] blob = cur.getBlob(cur.getColumnIndex("avatar_img"));
Bitmap bmp = BitmapFactory.decodeByteArray(blob, 0,blob.length, opts);
friend.setImage_bmp(bmp);

friend is and instance from a class havind a Bitmap property callend Image_bmp ;)

Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103
yeradis
  • 5,235
  • 5
  • 25
  • 26
  • Thanks. One other thing; How do I insert Latitude/Longtitude in the database and then to open google maps with intent? – user528057 Feb 18 '11 at 12:29
0

I've tried many methods to get this work, but until i made

cur.moveToFirst(); 

after query, i had null pointer here:

byte[] imageByteArray = cur.getBlob(cur.getColumnIndex("myImage"));
Roger Alien
  • 3,040
  • 1
  • 36
  • 46