sqlite数据库图像存储成功但更新无法正常工作。以blob类型存储图像

时间:2015-03-09 09:27:13

标签: android image sqlite blob

存储的图像在sqlite database.i中成功存储后,检索图像它也工作正常。但更新图像不工作。我找不到问题。没有错误显示更新后我检索图像但注意显示在图像视图

db.execSQL("CREATE TABLE if not exists producttable1(id INTEGER PRIMARY KEY AUTOINCREMENT,"
        + "subid TEXT,"
        + "submenue  TEXT,"
        + "submenut TEXT,"
        + "status TEXT,"
        + "submenuh TEXT,"
        + "rate TEXT,"
        +"photo BLOB,"      
        + "imgstat TEXT,"
        + "stackstat TEXT," + "noitem TEXT)");
public void addsubmenu(Model md) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("subid", md.subid);
contentValues.put("submenue", md.smenue);
contentValues.put("submenut", md.smenut);
contentValues.put("submenuh", md.smenuh);
contentValues.put("rate", md.rate);
contentValues.put("noitem", md.noitem);
contentValues.put("status", md.status);
contentValues.put("stackstat", md.stackstat);
contentValues.put("photo",md.photo);
contentValues.put("imgstat",md.imgstat);
db.insert("PRODUCTTABLE1", null, contentValues);
db.close();
}
     public void updateitem(Model productList) {
SQLiteDatabase db = this.getWritableDatabase();
//byte[] byteImage2 = null;
ContentValues contentValues = new ContentValues();
contentValues.put("id", productList.id);
contentValues.put("smenue", productList.smenue);
contentValues.put("smenut", productList.smenut);
contentValues.put("smenuh", productList.smenuh);
contentValues.put("rate", productList.rate);
contentValues.put("noitem", productList.noitem);
contentValues.put("photo",productList.photo);
contentValues.put("imgstat",productList.imgstat);   









db.execSQL("update producttable1 set submenue='" + productList.smenue
            + "',submenut='" + productList.smenut + "',submenuh='"
            + productList.smenuh + "',photo='"+productList.photo+"',imgstat='"+productList.imgstat+"',rate='" + productList.rate
            + "',noitem='" + productList.noitem + "' where id='"
            + productList.id + "'");    


db.close();

}

1 个答案:

答案 0 :(得分:1)

你可以试试这个。
正如您使用了内容值。

String where = "id=?";
String[] whereArgs = new String[] {String.valueOf(productList.id)};

db.update(DATABASE_TABLE, contentValues, where, whereArgs);