sqlite query failing - no such column

后端 未结 5 1898
梦谈多话
梦谈多话 2021-01-15 04:53

I have a db that is created like this...

public class DataBaseManager extends SQLiteOpenHelper{

    Context mContext;
    private static final String TAG =          


        
相关标签:
5条回答
  • 2021-01-15 04:54

    Change your old query "SELECT "+colID+ " FROM " + allScreens + " WHERE " + colName + "=" +name; to

     "SELECT "+colID+ " FROM " + allScreens + " WHERE " + colName + "='" +name+"'";
    
    0 讨论(0)
  • 2021-01-15 04:56

    Your query String is wrong

    String selectQuery = "SELECT "+colID+ " FROM " + allScreens + " WHERE " + colName + " = '" +name + "'";
    

    the name you give in where should be in single quotes

    0 讨论(0)
  • 2021-01-15 05:02

    Do it like this:

    String selectQuery = String.format("SELECT %s FROM %s WHERE %s = ?",
        colID, allScreens, colName);
    
    Cursor c = db.rawQuery(selectQuery, new String[]{name});
    
    0 讨论(0)
  • 2021-01-15 05:03

    Your query is wrong, as WHERE column = string will not work.

    String selectQuery = "SELECT "+colID+ " FROM " + allScreens + " WHERE " + colName + "=?";
    Cursor c = db.rawQuery(selectQuery, new String[] {name});
    

    Use ? which will be replaced by the second rawQuery() parameter. Strongly recommended.

    Not recommended: WHERE column = "string"

    0 讨论(0)
  • 2021-01-15 05:19

    name = DR_home means "column name equals column DR_home. You probably want to quote it if you want to string search (which I surmise you do, but I haven't peeked your code in depth since it's too long): name = 'DR_Home'.

    0 讨论(0)
提交回复
热议问题