How can I insert massive json data coming from the server into the Sqlite database on Android, very efficiently. The method I'm using now is very inefficient, and it takes almost a minute to complete the input of about 2000 entries. Next method:
for (int i = 0; i < jsonObj.length(); i++) { JSONObject itemObj = (JSONObject) jsonObj.get(i); ContentValues value1 = new ContentValues(); ContentValues value2 = new ContentValues(); value2.put(DbHelper.BusinessID,itemObj.getString("BusinessID")); value2.put(DbHelper.LocationID,itemObj.getString("LocationID")); JSONArray list = itemObj.getJSONArray("OfficeDetails"); if (list != null) { for (int k = 0; k < list.length(); k++) { JSONObject elem = list.getJSONObject(k); if (elem != null) { try { value1.put(DbHelper.Office_Code,elem.getInt("Office_Code")); value1.put(DbHelper.Office_District,elem.getInt("Office_District")); db.insert(DbHelper.MessageDetail,null, value1); } catch (Exception e) { e.printStackTrace(); } } db.insert(DbHelper.Message,null, value2); }
Incoming input is a nested Json array, which itself is nested. Is there a better way to quickly insert a huge amount of data in a very short time?
source share