No such column sqlite exception

后端 未结 3 442
长发绾君心
长发绾君心 2021-01-29 11:03

I am trying to get some data from user profile, but it doesn\'t find the column. I already check space between every query and it seems nothing wrong. Till now i can\'t see the

相关标签:
3条回答
  • 2021-01-29 11:39

    Use this

    String selectQuery = "SELECT * FROM " + TABLE_PROFILE + " WHERE " + KEY_USER_EMAIL + " = " + "'" + username + "'";
    

    Value of username needs to be passed as a string.

    0 讨论(0)
  • 2021-01-29 11:40

    In SQL, string literals must be quoted.

    However, to avoid formatting problems like this (and SQL injection attacks), use parameters instead:

    Cursor c = db.rawQuery("SELECT * FROM " + TABLE_PROFILE +
                           " WHERE " + KEY_USER_EMAIL + " = ?",
                           new String[]{ username });
    
    0 讨论(0)
  • 2021-01-29 12:02

    Isn't the KEY_USER_EMAIL column a string type? If that's the case, your where clause WHERE " + KEY_USER_EMAIL + " = " + username is trying to refer to the column value as KEY_USER_EMAIL = test1, whereas it should really refer / use it as,

    KEY_USER_EMAIL = 'test1' Just change your Where clause to like this -

    SELECT * FROM " + TABLE_PROFILE + " WHERE " + KEY_USER_EMAIL + " = '" + username + "'"
    
    0 讨论(0)
提交回复
热议问题