android - Hashmap into database -


i stored hashmap in database when items in hashmap more one, last value shown multiple times... example in hashmap have

bag

pen

book

but when retrieve values get

book

book

book

how fix this?

databasehandler.java

public void addquote(quote q, arraylist<hashmap<string, string>> put_q_list) {     mydatabase=this.getwritabledatabase();   try{     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 quote 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();    (hashmap<string, string> map : put_q_list) {        contentvalues cv = new contentvalues();        cv.put("quote_id", i);        cv.put("q_item_code", map.get("item_code_final"));        cv.put("q_item_desc", map.get("desc_final"));        cv.put("q_item_price", map.get("item_price_final"));        cv.put("q_item_qty", map.get("item_qty_final"));        cv.put("q_item_tax", map.get("item_tax_final"));        cv.put("q_item_discount", map.get("item_discount_final"));         mydatabase.insert("q_item", null, cv);     }  } 

add.java`

hashmap<string, string> map_item_final = new hashmap<string, string>();         map_item_final.put("item_code_final",autocomplete_item.gettext().tostring());         map_item_final.put("desc_final", item_desc.gettext().tostring());         map_item_final.put("item_price_final", string.valueof(item_price.gettext()));         map_item_final.put("item_tax_final",string.valueof(item_tax.gettext()));         map_item_final.put("item_discount_final",string.valueof(item_discount.gettext()));         map_item_final.put("item_qty_final", item_qty.gettext().tostring());         final_items.add(map_item_final); 

database.addquote(q, final_items);

retrieving....

public arraylist<hashmap<string, string>> getquoteitem(string quote_id)  {     arraylist<hashmap<string, string>> put_list= new arraylist<hashmap<string, string>>();      mydatabase=this.getwritabledatabase();     cursor cursor=mydatabase.rawquery("select * q_item quote_id="+integer.parseint(quote_id),null);      hashmap<string, string> map = new hashmap<string, string>(); while(cursor.movetonext())     {                map.put("i_item_code", cursor.getstring(1));                map.put("i_item_desc", cursor.getstring(2));                map.put("i_item_price", string.valueof(cursor.getint(3)));                map.put("i_item_qty", string.valueof(cursor.getint(4)));                map.put("i_item_tax", string.valueof(cursor.getfloat(5)));                map.put("i_item_discount", string.valueof(cursor.getint(6)));                put_list.add(map);     }  cursor.close();  return put_list;  } 

sqlite database browser

the first items becoming null!!! last item stored [img] https://drive.google.com/file/d/0b8fpyt_k7j81oxl0ejfizlpfrdq/edit?usp=sharing

please help!!!!

i think problem bit of code in add quote():

int i=0;  while(cursor.movetonext()) {      i=cursor.getint(0);  } 

you're storing value in cursor int, overwriting each time before it.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -