我有以下方法,执行时会出现错误:
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
);
答案 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
);