sqlite returned: error code = 1, msg = no such column:kitchen1

前端 未结 2 1517
暖寄归人
暖寄归人 2021-01-13 06:48

I\'ve been getting this error for two days now, and I can\'t find the problem with my code.

here\'s the database code.

SQLHandler.java

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 07:29

    If room is a character type (and it is, according to the CREATE_TABLE_2 string where it's defined as TEXT NOT NULL), you need to replace:

    KEY_ROOM + "=" + r
    

    with:

    KEY_ROOM + "= '" + r + "'"
    

    The way you have it, you're ending up with the query segment:

    where room = kitchen1
    

    and it's complaining that there's no kitchen1 column in that table, rightly so.

    By quoting it, you end up with the correct:

    where room = 'kitchen1'
    

    This will turn the cursor creation line into:

    Cursor c = ourDatabase.query(DATABASE_TABLE2, columns,
        KEY_ROOM + "='" + r + "'", null, null, null, null);
    //  ^^^^^^^^^^^^^^^^^^^^^^^^^
    //         Changed bit
    

提交回复
热议问题