Reputation: 2266
I have a query to insert image to db in android using sqlite.
String sqlQuerry = "INSERT table_name SET column_name = ? WHERE pk_id =last_insert_rowid();";
SQLiteStatement insertStmt = sqliteDataBase .compileStatement(sqlQuerry);
insertStmt.clearBindings();
insertStmt.bindBlob(1, byteArray);
insertStmt.execute();
But this shows sqlite returned: error code = 1, msg = near "SET": syntax error
How can i fix this?
Thanks in Advance
Upvotes: 0
Views: 188
Reputation: 33534
- The idea of storing image in the DB is not at all economic.
- On of the most practiced way of doing is, is to store the images in some folder on the sdcard
and then accessing that image using the path
stored in the DB.
- Once you have accessed the path
from DB, convert it into image.
Eg:
ImageView imageQuestion; // Declared at class scope
imageQuestion.setImageBitmap(BitmapFactory.decodeFile(/sdcard/myfolder/viv.png));
Upvotes: 1
Reputation: 25830
i will recommend you not to insert blobs
in db, this will make your db very very slow
Alternative solution is that You should save the image in documents directory of the app and in the db save only the path of the image.
Upvotes: 0
Reputation: 224859
I think you meant to use UPDATE
instead of INSERT
.
UPDATE table_name SET column_name = ? WHERE pk_id = last_insert_rowid();
Upvotes: 0