title: Hashmap into database
body: <p>I stored hashmap in database but when the items in hashmap are more than one, the last value is shown multiple times... for example in hashmap i have</p>
  
  <p>bag</p>
  
  <p>pen</p>
  
  <p>book </p>
  
  <p>but when I retrieve the values I get</p>
  
  <p>book</p>
  
  <p>book</p>
  
  <p>book</p>
  
  <p>How do I fix this?</p>
  
  <p>DatabaseHandler.java</p>
  
  <pre><code>public void addQuote(Quote q, ArrayList&lt;HashMap&lt;String, String&gt;&gt; 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 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();
  
    for (HashMap&lt;String, String&gt; 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);
      }
  
  }
  </code></pre>
  
  <p>Add.java`</p>
  
  <pre><code>HashMap&lt;String, String&gt; map_item_final = new HashMap&lt;String, String&gt;();
          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);
  </code></pre>
  
  <p>dataBase.addQuote(q, final_items);</p>
  
  <p>Retrieving....</p>
  
  <pre><code>public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getQuoteItem(String quote_id) 
  {
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; put_list= new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      myDataBase=this.getWritableDatabase();
      Cursor cursor=myDataBase.rawQuery("SELECT * from q_item where quote_id="+Integer.parseInt(quote_id),null);
  
      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  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;
  
  }
  </code></pre>
  
  <p>SQLite database browser</p>
  
  <p>The first items is becoming null!!! Only last item is stored
  [img]
  <a href="https://drive.google.com/file/d/0B8fPYT_K7J81OXl0ejFiZlpFRDQ/edit?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B8fPYT_K7J81OXl0ejFiZlpFRDQ/edit?usp=sharing</a> </p>
  
  <p>Please HELP!!!!</p>