Android 如何在数据库中插入图像?
我有一个使用sqlite在android中将图像插入db的查询Android 如何在数据库中插入图像?,android,insert,android-sqlite,Android,Insert,Android Sqlite,我有一个使用sqlite在android中将图像插入db的查询 String sqlQuerry = "INSERT table_name SET column_name = ? WHERE pk_id =last_insert_rowid();"; SQLiteStatement insertStmt = sqliteDataBase .compileStatement(sqlQuerry); insertStmt.clearBindings(); insertStmt.bindBlo
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,msg=near“SET”:语法错误
我怎样才能解决这个问题
提前谢谢我想你是想用
更新
而不是插入
更新表格名称集合列名称=?其中pk_id=最后一次插入_rowid()
我建议您不要在db中插入blob
,这会使您的db非常慢
另一种解决方案是,您应该将图像保存在应用程序的documents目录中,并在db中仅保存图像的路径。
-将图像存储在数据库中的想法根本不经济。 -最常用的方法之一是将图像存储在
SD卡上的某个文件夹中,然后使用数据库中存储的路径访问该图像。
-从DB访问路径后,将其转换为图像
例如:
ImageView imageQuestion; // Declared at class scope
imageQuestion.setImageBitmap(BitmapFactory.decodeFile(/sdcard/myfolder/viv.png));
否。我想插入图像。是否有任何方法可以在不使用ContentValues和execSQL()的情况下插入图像?@DevuSoman:因此,请使用插入表名(列名)值(?)代码>,我猜?