简体   繁体   中英

Column doesn't exist in android database

In my application I created a database and I tried to insert values into that table. But I received the following error:

 android.database.sqlite.SQLiteException: table income has no column named recurrence: , while compiling: INSERT INTO income(recurrence, salary, description) VALUES(?, ?, ?);

My code is:

Database creation:

"create table income(_id integer primary key autoincrement,"+"salary text not null,description text not null,"+"recurrence text not null);";

My insert query:

public long insertTitle(String income, String desc,String recurr)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_INCOME, income);
initialValues.put(KEY_DESC, desc);
initialValues.put(KEY_RECURR, recurr);
//initialValues.put(KEY_PUBLISHER, publisher);
return db.insert(DATABASE_TABLE, null, initialValues);
}

Try to clear your database form Android device. Maybe you application not overwriting the new database and using the old database. This may be a reason for this error.

Not sure exactly where it is going wrong but i suggest you go and check your database using adb . use following steps.

  1. Open command prompt
  2. Navigate to your android sdk folder-> platform tools
  3. adb -e shell
  4. cd data/data/your.package.name/databases
  5. sqlite3 YOUR_DATABASE.db
  6. Now run .tables or .schema income command
    OR select * from income;

you will get idea if your table has been created or not.

you can also write dummy insert command to check if it is working properly.

Insert into income values(1,"salary","desc","rec");

You missed a '+' sign:

Put this one and try:

"create table income(_id integer primary key autoincrement,"+"salary text not null,"+"description text not null,"+"recurrence text not null);";

And dont forget to Clear Data of your application before running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM