/** 修改专业 */ public boolean modifyMajor(Major major, String id) { ContentValues values = new ContentValues(); values.put("major_id", major.getMajor_id()); values.put("major_name", major.getMajor_name()); long l = db.update("major", values, "major_id=?", new String[] {id}); return l == 1; }
/** @param major 保存major到数据库 */ public boolean saveMajor(Major major) { if (major != null) { ContentValues values = new ContentValues(); values.put("major_id", major.getMajor_id()); values.put("major_name", major.getMajor_name()); long l = db.insert("major", null, values); if (l == -1) { return false; } else { return true; } } return false; }
/** @return 返回存有所有Major的List */ public List<Major> getMajor() { List<Major> list = new ArrayList<Major>(); Cursor cursor = db.query("major", null, null, null, null, null, null); while (cursor.moveToNext()) { Major major = new Major(); major.setMajor_id(cursor.getString(cursor.getColumnIndex("major_id"))); major.setMajor_name(cursor.getString(cursor.getColumnIndex("major_name"))); list.add(major); } if (cursor != null) { cursor.close(); } return list; }