简体   繁体   中英

No Such Column Error In Android SQLite

I created database. But it gives me "no such column error". I'm sure that my database have that coloumn because i used SQLite Manager to add data. I don't understand why i am getting such error. I've searched this question here, but the answers never helped me.

Most of answers says that If there is no space between column name while writing this code, it gives this error. But i think i writed correctly.

public void onCreate(SQLiteDatabase sqLiteDatabase) {
    sqLiteDatabase.execSQL(
            "CREATE TABLE " + TABLE_NAME + " ("
           + BNUM_COL + " TEXT, " 
          + PNAME_COL + " TEXT, " 
          + AUTHOR_COL + " TEXT, " 
           + TYPE_COL + " TEXT, " 
           + PYEAR_COL + "INTEGER );");
  }

My Logcat also showed me :

Cursor c = db.query("btable", SELECT, null, null, null, null, null, null);

Please help me.

The last field has no space between the column name and the keyword INTEGER . You need to change this line:

+ PYEAR_COL + "INTEGER );");

to this:

+ PYEAR_COL + " INTEGER );");
               ^
               |
               Note the extra space!

A simple diagnostic tool to help track down these kinds of errors is to store the SQL query in a variable and log it before trying to execute it. Then you can examine the logcat output to see what statement was actually built.

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