· 8 years ago · Mar 29, 2018, 03:42 PM
1public DataBaseHelper(Context context) {
2 super(context, DATABASE_NAME, null, version);
3 }
4
5 @Override
6 public void onCreate(SQLiteDatabase db) {
7
8 String q = "CREATE TABLE IF NOT EXISTS " + TABLE_NAMETRY + "(" +
9 COL_ID + " INTEGER PRIMARY KEY, " + COL_NAME + " TEXT, " + COL_PHONE + " TEXT " + ")";`enter code here`
10 db.execSQL(q);
11 }
12 @Override
13
14 public void onUpgrade(SQLiteDatabase db, int i, int i1) {
15 db.execSQL("DROP table if exist "+TABLE_NAMETRY);
16 onCreate(db);
17 }
18
19 public boolean insertData(String name,String no)
20 {
21 SQLiteDatabase db = this.getWritableDatabase();
22 ContentValues contentvalue = new ContentValues();
23 contentvalue.put(COL_NAME,name);
24 contentvalue.put(COL_PHONE,no);
25 long result = db.insert(TABLE_NAMETRY,null,contentvalue);
26 if(result==-1)
27 return false;
28 else
29 return true;
30 }
31
32insertOrThrow