public boolean refreshData(String json, String courseID) { getDatabase(); ContentValues value = new ContentValues(); value.put("course_data", json); value.put("course_id", courseID); value.put("time", System.currentTimeMillis()); int num = db.update(ConstantUtils.T_COURSE_DATA, value, "course_id = ?", new String[] {courseID}); if (num == 0) { long num2 = db.insert(ConstantUtils.T_COURSE_DATA, null, value); if (num2 == -1) { return false; } else { return true; } } return true; }
@Override public void handleMessage(Message msg) { if (progressBar.VISIBLE == View.VISIBLE) { progressBar.setVisibility(View.GONE); } if (msg.what == 0) { // success CourseDBManager db = new CourseDBManager(LoginActivity.this); db.getDatabase(); List<HashMap<String, String>> data = db.queryEnrollment(Utils.getUserName()); Intent intent = new Intent(LoginActivity.this, MainActivity.class); intent.putExtra("data", (ArrayList) data); startActivity(intent); db.closeDB(); LoginActivity.this.finish(); } if (msg.what == -1) { Toast.makeText(LoginActivity.this, msg.obj.toString(), Toast.LENGTH_LONG).show(); } }
private boolean refresh(List<HashMap<String, Object>> data, String table) { getDatabase(); db.beginTransaction(); try { db.execSQL("delete from " + table); for (HashMap<String, Object> item : data) { ContentValues values = new ContentValues(); Iterator iter = item.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); values.put(entry.getKey().toString(), entry.getValue().toString()); } db.insert(table, null, values); } db.setTransactionSuccessful(); return true; } catch (Exception e) { return false; } finally { db.endTransaction(); } }