contoh aplikasi crud android sqlite dan cara import

Solutions on MaxInterview for contoh aplikasi crud android sqlite dan cara import by the best coders in the world

showing results for - "contoh aplikasi crud android sqlite dan cara import"
Jessica
22 Aug 2018
1import android.content.Context;
2import android.database.sqlite.SQLiteDatabase;
3import android.database.sqlite.SQLiteOpenHelper;
4
5public class DBHelper extends SQLiteOpenHelper {
6
7    private static final int DATABASE_VERSION = 1;
8
9    private static final String DATABASE_NAME = "cruddb";
10    protected static final String TABLE_NAME = "crud";
11
12    public DBHelper(Context context) {
13        super(context, DATABASE_NAME, null, DATABASE_VERSION);
14        //context.deleteDatabase(DATABASE_NAME); //buka ini untuk delete database
15    }
16
17    @Override
18    public void onCreate(SQLiteDatabase db) {
19        //membuat kolom id dg tipe integer dan sebagai primary key, dan input dg tipe text
20        String sqlMutabaah = "CREATE TABLE " + TABLE_NAME + " " +
21                "( ID INTEGER PRIMARY KEY, INPUT TEXT ) ";
22        db.execSQL(sqlMutabaah);
23    }
24
25    @Override
26    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
27        String sql = "DROP TABLE IF EXISTS " + TABLE_NAME + "";
28        db.execSQL(sql);
29        onCreate(db);
30    }
31}