Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.demo.bloodpressure;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- public class BPData extends SQLiteOpenHelper {
- public BPData(Context context) {
- super(context, "bp.db", null, 1);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL("create table bps ("
- + "_ID INTERGER PRIMARY KEY AUTOINCREMENT, "
- + "SYSTOLIC TEXT, "
- + "DIASTOLIC TEXT, "
- + "HEARTREATE TEXT, "
- + "BPDATE DATETIME DEFAULT CURRENT_TIMESTAMP);");
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL("DROP TABLE IF EXISTS bps");
- onCreate(db);
- }
- public void create(String systolic, String diastolic, String heartrate) {
- SQLiteDatabase wd = getWritableDatabase();
- ContentValues cv = new ContentValues();
- cv.put("SYSTOLIC", systolic);
- cv.put("DIASTOLIC", diastolic);
- cv.put("HEARTRATE", heartrate);
- wd.insert("bps", null, cv);
- }
- public String[] list() {
- SQLiteDatabase rd = getReadableDatabase();
- Cursor cur = rd.query("bps",
- new String[] { "SYSTOLIC",
- "DIASTOLIC",
- "HEARTRATE" },
- null,
- null,
- null,
- null,
- null);
- String[] row = new String[cur.getCount()];
- int cnt = 0;
- if (cur.getCount() > 0) {
- while (cur.moveToNext()) {
- String line = "Systolic: " + cur.getString(1);
- row[cnt] = line;
- cnt++;
- }
- }
- return row;
- }
- }
Add Comment
Please, Sign In to add comment