如何保存ArrayList < HashMap < String >>在數據庫中?將arrayList散列表保存到數據庫中
獲取NULL值在數據庫
這個方法我試過:Saving records into the database from the hashmap in android 但並沒有幫助
public void addQuote(Quote q, ArrayList<HashMap<String, String>> put_q_list)
{
try{
myDataBase=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("q_customer_name", q.getCustomer_name());
values.put("q_customer_email", q.getCustomer_email());
values.put("q_b_street", q.getBilling_street());
values.put("q_b_city", q.getBilling_city());
values.put("q_b_state", q.getBilling_state());
values.put("q_b_zipcode", q.getBilling_zipcode());
values.put("q_b_country", q.getBilling_country());
values.put("q_s_street", q.getShipping_street());
values.put("q_s_city", q.getShipping_city());
values.put("q_s_state", q.getShipping_state());
values.put("q_s_zipcode", q.getShipping_zipcode());
values.put("q_s_country", q.getShipping_country());
values.put("q_day", q.getDay());
values.put("q_month", q.getMonth());
values.put("q_year", q.getYear());
values.put("q_total", q.getTotal());
values.put("q_discount", q.getTotal_discount());
myDataBase.insert("quote",null,values);
}catch(Exception e)
{
Log.e("bderror",e.toString());
e.printStackTrace();
}
String selectQuery = "SELECT quote_id FROM quote WHERE q_customer_email=?";
Cursor cursor = myDataBase.rawQuery(selectQuery, new String[] {q.getCustomer_email()});
int i=0;
while(cursor.moveToNext())
{
i=cursor.getInt(0);
}
cursor.close();
myDataBase.beginTransaction();
for (int j = 0; j < put_q_list.size(); j++) {
HashMap<String, String> map = new HashMap<String, String>();
map = put_q_list.get(j);
//Each value by using this method
String item_code = map.get("item_code_final");
ContentValues cv = new ContentValues();
cv.put("quote_id", i);
cv.put("q_item_code", item_code);
myDataBase.insert("q_item", null, cv);
}
myDataBase.setTransactionSuccessful();
myDataBase.endTransaction();
myDataBase.close();
}
只有的值 「i」 被插入!不是產品代碼 請幫忙!!!
什麼是你的代碼,你用過的?? – MDMalik
編輯問題 – DICER45
現在試試,我想你的'i'變量是問題\ – MDMalik