I have created a sub class (DatabaseHelper) of SQLiteOpenHelper Class.Its has a constructor and two overriden methods
public DatabaseHelper(Context context) {
super(context, dbName, null,33);
// TODO Auto-generated constructor stub
}
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE "+ quizTable +"("+quizCol1+" INTEGER PRIMARY KEY,"+
quizCol2+" TEXT,"+ quizCol3 +" TEXT,"+ quizCol4 +" INTEGER," + quizCol5 + " DATETIME )");
db.execSQL("CREATE TABLE "+ questionTable +"("+questionCol1+" INTEGER PRIMARY KEY,"+
questionCol2+" INTEGER,"+ questionCol3 +" TEXT,"+ questionCol4 +" TEXT," + questionCol5 + " TEXT," +
questionCol6 + " TEXT," + questionCol7 +" TEXT," + questionCol8 +" TEXT)");
db.execSQL("CREATE TABLE "+ playedQuizzes +"("+playedQuizCol1+" INTEGER PRIMARY KEY,"+
playedQuizCol2+" TEXT,"+ playedQuizCol3 +" TEXT,"+ playedQuizCol4 +" TEXT," +
playedQuizCol5 + " TEXT)");
System.out.println("this is onCreate method");
InsertQuiz();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS "+questionTable);
db.execSQL("DROP TABLE IF EXISTS "+playedQuizzes);
onCreate(db);
}
In my Activity subclass i have called the constructor of above class using
public void onStart(){
try{
super.onStart();
dbHelper = new DatabaseHelper(this);
}catch(Exception ex){
CatchError(ex.toString());
}
}
But when i run my Activity class and open my DDMS perspective then i did not find any database created under /data/data/
Is there something wrong with my knowlege or my code? If yes please tell me.
From the documentation of the SQLiteOpenHelper class:
So the database doesn’t get created before not calling getWritableDatabase() or getReadableDatabase().