SQLiteException:没有这样的列:(代码1)

时间:2014-11-09 12:18:13

标签: android sqlite

我有以下方法,执行时会出现错误:

  

11-09 12:11:17.578:E / AndroidRuntime(21018):引起:   android.database.sqlite.SQLiteException:没有这样的列:happy(代码   1):,编译时:select * from Bank where english = happy

方法是:

public boolean BankHas(Word currentWord) {
        openDataBase();
        Cursor cursor = myDataBase.rawQuery("select * from Bank where english = " + currentWord.english, null); 
        return cursor.moveToFirst();
    }

我的表格方案:

CREATE TABLE `Bank` (
    `english`   TEXT
);

1 个答案:

答案 0 :(得分:8)

你错过了单引号,所以改变

"select * from Bank where english = " + currentWord.english

"select * from Bank where english ='" + currentWord.english + "'"

推荐的解决方案是使用参数化查询作为

Cursor cursor = myDataBase.rawQuery("select * from Bank where english =? ", new String [] {currentWord.english});

更改您的创建表格
CREATE TABLE `Bank` (
    `english`   TEXT
);

CREATE TABLE Bank (
    english TEXT
);