try to extend the SQLiteOpenHelper class
and try to override the onCreate and place the query in the onCreate method
Java version
public class DatabaseHelper extends SQLiteOpenHelper {
....
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
SQLiteDatabase db = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
// creating required tables
db.execSQL(create table query goes here);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// on upgrade drop older tables
db.execSQL("DROP TABLE IF EXISTS tablename" );
// create new tables
onCreate(db);
}
...
...
}
SQLiteOpenHelper helper class to manage database creation and version management.
You create a subclass implementing
onCreate , onUpgrade and
optionally onOpen , and this class takes care of opening the database
if it exists, creating it if it does not, and upgrading it as necessary.
onCreate
Called when the database is created for the first time.
onUpgrade
Called when the database needs to be upgraded. this method should be used to drop tables, add tables