ervinne

Revised getStudentById

Apr 22nd, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. @Override
  2. public ProfileTableActivity getStudentById(int Id) {
  3. SQLiteDatabase db = dbHelper.getReadableDatabase();
  4.  
  5. String whereClause = ProfileTableActivity.KEY_ID + "=?";
  6. String[] whereArgs = {Integer.toString(Id)};
  7.  
  8. ProfileTableActivity student = new ProfileTableActivity();
  9.  
  10. Cursor cursor = db.query(
  11. ProfileTableActivity.TABLE,
  12. ProfileTableActivity.COLUMN_COLLECTION,
  13. whereClause,
  14. whereArgs,
  15. null, null, null);
  16.  
  17. if (cursor.moveToFirst()) {
  18. do {
  19. student.student_ID =cursor.getInt(cursor.getColumnIndex(ProfileTableActivity.KEY_ID));
  20. student.name =cursor.getString(cursor.getColumnIndex(ProfileTableActivity.KEY_name));
  21. student.email =cursor.getString(cursor.getColumnIndex(ProfileTableActivity.KEY_email));
  22. student.age =cursor.getInt(cursor.getColumnIndex(ProfileTableActivity.KEY_age));
  23.  
  24. } while (cursor.moveToNext());
  25. }
  26. cursor.close();
  27. db.close();
  28. return student;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment