NewbieCoder NewbieCoder - 26 days ago 20
Android Question

Android SQLite Table out of range

When I tried to insert 5 values into my SQLite Database, it says as follows in the LogCat:

android.database.sqlite.SQLiteException: table student has 3 columns but 5 values were supplied (code 1): , while compiling: INSERT INTO student VALUES('csd13','asdasd','12316456','23','12313');


And this is my table creation code.

db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR, name VARCHAR, phone VARCHAR, age VARCHAR, city VARCHAR);");


As you can see, I have initialized 5 fields in the table but why am I not allowed to put in 5 values and it says has ONLY 3 columns.

My insert query is as follow:

db.execSQL("INSERT INTO student VALUES('"+editRollno.getText()+"','"+editName.getText()+ "','"+editPhone.getText()+"','"+editAge.getText()+"','"+editCity.getText()+"');");

Answer

It's because I have FIRST initialized the same table name with 3 fields, and then I edited it into 5. So Basically, change the name of the table OR delete the table from the database in Eclipse.

Comments