我想使用插入或替换查询,在这里我给出的代码

  String sql="insert or replace into Stock_Table values (?,?,?,?,?,?)";

  sqlite.execSQL(sql, new String[]{id,name,code,vat,itmquan,pric});


现在我想在此表中另外插入一个字段,但该字段不是字符串
它是一种字节数组格式,我想在该表中添加一个图像,我将该图像的数据类型指定为表中的BLOB,但是我无法将字节数组格式作为参数传递给上述sqlite.execsql函数,此处我给我想要插入的格式

byte []byteImage;

String sql="insert or replace into Stock_Table values (?,?,?,?,?,?,?)";

sqlite.execSQL(sql, new String[]{id,name,code,vat,itmquan,pric,byteImage});


我如何使它成为可能,我无法将该字节数组转换为字符串,我只想将图像插入为BLOB格式,请帮助我找到任何解决方案

最佳答案

使用insert method的变体,该变体采用ContentValues object,它允许您直接使用字节数组:

byte[] byteImage;
ContentValues cv = new ContentValues();
cv.put("id", id);
// ...
cv.put("blobcolumn", byteImage);
sqlite.insertWithOnConflict("Stock_Table", null, cv, SQLiteDatabase.CONFLICT_REPLACE);

关于android - android中的sqlite.execSQL函数传递参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16771580/

10-09 15:45