Am creating a new database using helper, but as per the document on create should be called once the data base is created, but its not called properly. could any plz help me to resolve this asap. Plz see the code below.
1) Is there any way to create database instead of using helper if so plz advise me ! 2) What are the callbacks will be called in the database creation and also in kill of a database ?
OpenHelper(Context context)
{
super(context, "examplee.db", null, 1 );
SQLiteDatabase sqlite = null;
Log.w(TAG, "Openhelp database, ");
sqlite = context.openOrCreateDatabase("examplee.db", Context.MODE_PRIVATE, null );
Log.e ( TAG,"SQ lite database object "+sqlite );
}
public void onOpen(SQLiteDatabase db)
{
Log.e ( TAG,"On open called ");
}
@Override
public void onCreate(SQLiteDatabase db)
{
Log.w(TAG, " On create ");
//db.execSQL(sql);
//db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database, this will drop tables and recreate.");
//db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
//onCreate(db);
}
}
Thanks in advance,
Here's a very detailed description on how to delete a database file from your emulator (debugging on an actual android phone is very similar).
Run your emulator. If you're having problems with that, then you can ignore the rest of this help message!
Pull up a command-line interface, according to your operating system.
Execute the command: 'adb shell' (omit the quotes, of course). This will take you into the Android Debug Bridge; your prompt will change to something like a simple pound sign. Regardless of your original operating system, you are now in a simplified unix OS.
You are now in your emulator. Type the command 'ls -l' to verify that you're in the root directory (you'll see something that looks very much like a unix root directory system).
Change directories to where your database file is stored. Suppose that the program that your ran is in the package com.sillynames.myprogram5, and the database file is called 'myblackbook.db'. You will find the file at the directory:
/data/data/com.sillynames.myprogram5/databases/myblackbook.db
Once you're at that directory, simply delete the database via 'rm myblackbook.db'.
Hope this helps! -scott
The SQLiteOpenHelper javadoc says that onCreate is "Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.". It is not called everytime the application comes up. In your case Probably the db is already created.
To verify if the db exists login to the shell with adb and go to /data/data/<your application package name>/databases and see if the employees.db file exists there.
In the onCreate method typically you will create your tables and load any initial data. This is executed when the app is launched for the first time after installation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With