简体   繁体   中英

android: how to load sqlite data in hashtable

I'm new to java and android. I want to get sqlite rows in a hashtable and then send them to server like a data set. I never use hash table before, as hash table takes two parameters key and value, i don't know how to pass the key can anybody tell me what is the correct way to achieve this.

  public Hashtable<String,ChemOrderDetailTable> getDetail(){

       db = DBHelper.getWritableDatabase();
       Cursor c= db.query(DB_TABLE_CHEMIST_ORDERS_DETAIL, null, null, null, null, null, null, null);
       Hashtable<String,ChemOrderDetailTable> hashtable = 
             new Hashtable<String,ChemOrderDetailTable>();
       if (c != null) {
             while (c.moveToNext()) {

                 String orderNo = c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_ORDERNO));
                 String prodCode = c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_PRODCODE));
                 String qty= c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_QTY));
                 String tp= c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_TYP));
                 String total = c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_AMOUNT));

                 ChemOrderDetailTable chemDetailTable = new ChemOrderDetailTable();
                 chemDetailTable.setOrderNo(orderNo);
                 chemDetailTable.setProdCode(prodCode);
                 chemDetailTable.setQTY(qty);
                 chemDetailTable.setOrderNo(tp);
                 chemDetailTable.setTotal(total);

                 hashtable.put(key, chemDetailTable);

             }
          } 
     return hashtable; 

 }

sending hashtable to server

JSONObject json = new JSONObject();
json.putAll(hashtable);

send json.toString() as a payload in API

我建议您使用默认列_id作为键,因为它们是行的唯一标识符。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM