JSON data arraylist and sqlite data arraylist compared to each other after compare data not same after inserted in sqlite database in android -
json data stored in arraylist , sqlite data stored arraylist. 2 database compare each other.in json arraylist new updated data stored in database.json , sqlite database data not same after stored in sqlite database. or give me easy way json data stored in sqlite database.
mainactivity
try { jsonarray jsonarray = new jsonarray(s); if(jsonarray != null){ (int = 0; < 1 ;i++) { jsonobject jsonobject = jsonarray.getjsonobject(i); studentname = jsonobject.getstring("studentname"); rollno = jsonobject.getdouble("rollno"); standard = jsonobject.getstring("standard"); division = jsonobject.getstring("division"); fatherno = jsonobject.getdouble("smsno"); address = jsonobject.getstring("std_address"); school = jsonobject.getstring("schoolname"); image = jsonobject.getstring("imagepath"); stdid = jsonobject.getlong("stdid"); divid = jsonobject.getlong("divisionid"); string date = jsonobject.getstring("dob"); string replacedate = date.replace("/date(", "").replace(")/", ""); long getdate = long.valueof(replacedate); dob = dateformat.format(getdate); hashmap<string, string> map = new hashmap<string, string>(); // map.put("id", cursor.getstring(0)); map.put("username", studentname); map.put("dob", dob); map.put("rollno", string.valueof(rollno)); map.put("std", standard); map.put("div", division); map.put("mobileno", string.valueof(fatherno)); map.put("address", address); map.put("school", school); jsonlist = new arraylist<>(); jsonlist.add(map); } dbhelper db = new dbhelper(getapplicationcontext()); arraylist<hashmap<string,string>> list = db.getallregistrationdata(); (int j = 0; j< jsonlist.size(); j++ ){ (int k = 0; k < list.size(); k++){ if (jsonlist.get(j).equals(list.get(k))){ toast.maketext(registration_activity.this, "alredy exist", toast.length_short).show(); }else { long id = db.insertregistration(studentname,rollno,standard,division,fatherno,address,school,dob); toast.maketext(registration_activity.this, "insert id : " + id, toast.length_short).show(); } } } } } catch (jsonexception e) { e.printstacktrace(); }
dbhelper
public arraylist<hashmap<string,string>> getallregistrationdata(){ arraylist<hashmap<string,string>> list = new arraylist<hashmap<string, string>>(); sqlitedatabase db = getreadabledatabase(); cursor cursor = db.rawquery("select * "+table_registration,null); if (cursor.movetofirst()) { { hashmap<string, string> map = new hashmap<string, string>(); map.put("id", cursor.getstring(0)); map.put("username", cursor.getstring(1)); map.put("dob", cursor.getstring(2)); map.put("rollno", cursor.getstring(3)); map.put("std", cursor.getstring(4)); map.put("div", cursor.getstring(5)); map.put("mobileno", cursor.getstring(6)); map.put("address", cursor.getstring(7)); map.put("school", cursor.getstring(8)); list.add(map); } while (cursor.movetonext()); } return list; }
Comments
Post a Comment