1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
| package com.example.ayushi.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME="DbApp";
public static final int DATABASE_VERSION=1;
public static final String TABLE = "DbTable";
public static final String _ID = "id";
public static final String COLUMN_1="Task";
public static final String COLUMN_2="status";
public static final String CREATE_TABLE="CREATE TABLE "
+ TABLE + " ( "
+ _ID + " INTEGER PRIMARY KEY, "
+ COLUMN_1 + " TEXT, "
+ COLUMN_2 + " TEXT)";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void addData(String s1,String s2)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_1,s1);
values.put(COLUMN_2,s2);
db.insert(TABLE,null,values);
db.close();
}
public Cursor fetchData()
{
SQLiteDatabase db = this.getReadableDatabase();
String str = ("SELECT rowid _id, * FROM DbTable");
return db.rawQuery(str,null);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE);
onCreate(db);
}
}
|