Android 2.3.3
static String name = "Database";
static int version = 1;
static SQLiteDatabase sqlDB;
static Cursor c;
public Database(Context context) {
super(context, name, null, version);
// TODO Auto-generated constructor stub
sqlDB = getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase sqlDB) {
// TODO Auto-generated method stub
sqlDB.execSQL("create table if not exists Operations(Command Text, Pos1 Text, " +
"Pos2 Text, Pos3 Text, Pos4 Text, Pos5 Text, Pos6 Text, Pos7 Text, Pos8 Text, Pos9 Text, Pos10 Text)");
insertData();
}
private void insertData() {
// TODO Auto-generated method stub
String addQuery ="ADD, add, and, had, ad, anddd, anndd, null, null, null, null";
sqlDB.execSQL("insert into Operations values("+ addQuery +")");
//Exception at the above line
}
There are a total of 11 columns.
Can i insert NULL into the database?
If yes, is there any problem with the way i am trying to insert the data into the database?
As pointed out by rekire, it seems the problem is with the getWritableDatabase(). I am calling the constructor with , Database db = new Database(this); which worked in all other projects till now, as i have declared the local variables for name and version and provided null to the factory.
Answer ::: Sorry it’s my mistake. I called a method in the database,
by using Database.method(), instead of it’s object(db). This made the
SQLiteDatabase and Cursor objects to be static in the Database.java
file. When i changed it to db.method(), and removed the static
keyword, it works fine.
Thanks for your time.. And sorry for the trouble.
If I guess right than your function
getWritableDatabase()returns null.