Guest User

Untitled

a guest
Jun 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package com.demo.bloodpressure;
  2.  
  3. import android.content.ContentValues;
  4. import android.content.Context;
  5. import android.database.Cursor;
  6. import android.database.sqlite.SQLiteDatabase;
  7. import android.database.sqlite.SQLiteOpenHelper;
  8.  
  9. public class BPData extends SQLiteOpenHelper {
  10.  
  11. public BPData(Context context) {
  12. super(context, "bp.db", null, 1);
  13. }
  14.  
  15. @Override
  16. public void onCreate(SQLiteDatabase db) {
  17. db.execSQL("create table bps ("
  18. + "_ID INTERGER PRIMARY KEY AUTOINCREMENT, "
  19. + "SYSTOLIC TEXT, "
  20. + "DIASTOLIC TEXT, "
  21. + "HEARTREATE TEXT, "
  22. + "BPDATE DATETIME DEFAULT CURRENT_TIMESTAMP);");
  23. }
  24.  
  25. @Override
  26. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  27. db.execSQL("DROP TABLE IF EXISTS bps");
  28. onCreate(db);
  29. }
  30.  
  31. public void create(String systolic, String diastolic, String heartrate) {
  32. SQLiteDatabase wd = getWritableDatabase();
  33. ContentValues cv = new ContentValues();
  34. cv.put("SYSTOLIC", systolic);
  35. cv.put("DIASTOLIC", diastolic);
  36. cv.put("HEARTRATE", heartrate);
  37. wd.insert("bps", null, cv);
  38. }
  39.  
  40. public String[] list() {
  41.  
  42. SQLiteDatabase rd = getReadableDatabase();
  43.  
  44. Cursor cur = rd.query("bps",
  45. new String[] { "SYSTOLIC",
  46. "DIASTOLIC",
  47. "HEARTRATE" },
  48. null,
  49. null,
  50. null,
  51. null,
  52. null);
  53.  
  54. String[] row = new String[cur.getCount()];
  55.  
  56. int cnt = 0;
  57.  
  58. if (cur.getCount() > 0) {
  59. while (cur.moveToNext()) {
  60. String line = "Systolic: " + cur.getString(1);
  61. row[cnt] = line;
  62. cnt++;
  63. }
  64. }
  65.  
  66. return row;
  67.  
  68. }
  69. }
Add Comment
Please, Sign In to add comment