gpt4 book ai didi

android - 在android中使用sqlite.execSQL函数传递参数

转载 作者:行者123 更新时间:2023-11-29 00:29:26 26 4
gpt4 key购买 nike

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

  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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com