I have created a helper class to connect with my sqlite database, but I don't know how to call it to actually create database in /data folder in android.
This is my OpenHelper class:
public class DBHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "database.db";
private static final String TAG = DBHelper.class.getSimpleName().toString();
public DBHelper(Context context)
{
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(categoryRepo.createTable());
db.execSQL(word_polRepo.createTable());
db.execSQL(word_engRepo.createTable());
db.execSQL(wordRepo.createTable());
db.execSQL(sentenceRepo.createTable());
Log.d(TAG,"Database creating...");
Log.d(TAG, "Table" +category.TABLE + "ver."+DATABASE_VERSION + "created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + category.TABLE);
onCreate(db);
}
I want this class to execute and create database when app starts.
I tried something like this in MainActivity.java but it's not good.
DBHelper db = new DBHelper(this);
db.onCreate() ???