Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.channel;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.SQLException;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- public class Database {
- public static final String KEY_ROWID = "_id";
- public static final String KEY_NAME = "p_name";
- public static final String KEY_RLT = "p_rlt";
- private static final String DB_NAME = "People";
- private static final String DB_TABLE = "PT";
- private static final int DB_VERSION = 1;
- private static DbHelper ourHelper;
- private SQLiteDatabase ourDatabase;
- private static Context ourContext;
- public Database(Context c) {
- ourContext = c;
- }
- private static class DbHelper extends SQLiteOpenHelper {
- public DbHelper(Context context) {
- super(context, DB_NAME, null, DB_VERSION);
- // TODO Auto-generated constructor stub
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- db.execSQL("CREATE TABLE " + DB_TABLE + " (" + KEY_ROWID
- + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME
- + " TEXT NOT NULL, " + KEY_RLT + " TEXT NOT NULL);");
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
- // TODO Auto-generated method stub
- db.execSQL("DROP TABLE IF EXIST " + DB_TABLE);
- onCreate(db);
- }
- }
- public Database open() throws SQLException
- {
- ourHelper = new DbHelper(ourContext);
- ourHelper.getWritableDatabase();
- return this;
- }
- public Database close()
- {
- ourHelper.close();
- return this;
- }
- public void addThat(String data) {
- // TODO Auto-generated method stub
- ContentValues cv = new ContentValues();
- cv.put(KEY_NAME, data);
- cv.put(KEY_RLT, "brother");
- ourDatabase.insert(DB_TABLE, null, cv);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement