How to execute pre-database sql statements?
How can we execute pre-database sqlite statements in Android?
I have created my own database layer. This layer will create the database and even the queries. It has a method that will create the table by providing the table name, column names and column types as parameters to it and the table will be generated without writing the full length query. So, to implement this I have created a test application and inside the onCreate
method I have used my method that is going to generate the CREATE TABLE
que开发者_如何学Pythonry and execute it. But as the database is not yet created it's throwing a NullPointerException.
So how can I fix this exception?
You need to use OpenHelper for this. Override it's OnOpen method to make actions on database open.
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#onOpen%28android.database.sqlite.SQLiteDatabase%29
http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/
精彩评论