数据库更新后,Android数据库cursor.moveToFirst返回false

时间:2014-12-03 10:01:00

标签: android

我是android的新手,在下面的代码中,我正在从数据库中检索内容并使用哈希映射数组列表更新内容。一旦数据更新,cursor.moveTofirst将返回false。这些是选择和更新的功能。

  // select function
public Product getProduct(String id) {

    SQLiteDatabase db = this.getReadableDatabase();
    String selectQuery = "SELECT * FROM POSGROCESSORYDETAILS WHERE itemId ='" + id + "'";
    Cursor cursor = db.rawQuery(selectQuery, null);
    Product product = null;
    Log.d("CURSOR", "outside if condition");
    if(cursor.moveToFirst()){
        Log.d("CURSOR", "inside if condition");
        product = new Product(cursor.getString(0), cursor.getString(1), cursor.getString(2),
                    cursor.getString(3), cursor.getString(4), cursor.getString(5));
    }

    cursor.close();
    db.close();
    return product;
}
 //Update database 
 public void updatedata(ArrayList<HashMap<String, String>> dataListArray)
{
    SQLiteDatabase database = this.getWritableDatabase();
    for (int i = 0; i < dataListArray.size(); i++) {
            HashMap<String, String> map = new HashMap<String, String>();
            map = productListArray.get(i);  
            ContentValues cv = new ContentValues();
            cv.put("itemId", map.get(ITEMCODE_COLUMN));
            cv.put("itemDesc", map.get(ITEMDESCRIPTION_COLUMN));
            cv.put("itemUnitprice", map.get(UNITPRICE_COLUMN));
            cv.put("itemQuantity", map.get(QUANTITY_COLUMN));
            cv.put("itemUnit", map.get(MEASUREMENT_COLUMN));
            cv.put("itemTotalprice", map.get(TOTALPRICE_COLUMN)); 
            database.update(TABLE_DATADETAILS, cv, KEY_ITEMID="?",new String[] {map.get(ITEMCODE_COLUMN)});
    }
    database.close();   
} 

调用update函数后,只有cursor.moveToFirst返回false

0 个答案:

没有答案