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

前端 未结 2 1516
暖寄归人
暖寄归人 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:20

    When trying to input strings for dummy data, you should call INSERT VALUES ("'text'") instead of INSERT VALUES ( "text" )

    Explanation : Because the sql command will want to see a quote ' around the text and the outer quotes " is for java to recognise that what you are trying to pass in / concatenate is a string

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题