2013-01-08 156 views
0

我有一个查询插入图像到数据库在android中使用sqlite。如何在db中插入图像?

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(); 

但是这表明sqlite的返回:错误码= 1,味精=近 “SET”:语法错误

我怎么能解决这个问题?

由于提前

回答

0

我想你想用UPDATE而不是INSERT

UPDATE table_name SET column_name = ? WHERE pk_id = last_insert_rowid();
+0

Ⅰ号要插入image.Is有什么办法可以插入图像,而无需使用ContentValues和使用execSQL()? –

+1

@DevuSoman:所以使用INSERT INTO table_name(column_name)VALUES(?);',我猜? – Ryan

0

我会建议你不要插入数据库blobs这会让你的数据库非常非常慢

替代的解决方案是,你应该将图像保存在应用程序的文件目录并在数据库中只保存图像的路径。

1

-在数据库存储图像的想法是不是在所有的经济。

-在做着是的最练方式,是Store上sdcard然后在某些文件夹中的图片使用存储在数据库中path访问该图像。

-一旦进入从DB的path其转换成图像

如:

ImageView imageQuestion; // Declared at class scope 

imageQuestion.setImageBitmap(BitmapFactory.decodeFile(/sdcard/myfolder/viv.png));