Logcat:
android.database.sqlite.SQLiteException:无此类列:kelime(代码
1):,而在编译时:SELECT * FROM Mylist WHERE名称= kelime
但我的栏不是“基莱姆”,而是“名称”。
我的资料库
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS \"Words\" (\n" +
"\t\"Id\"\tINTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" +
"\t\"Name\"\tTEXT,\n" +
"\t\"Mean\"\tTEXT\n" +
");");
db.execSQL("CREATE TABLE IF NOT EXISTS \"MyList\" (\n" +
"\t\"Id\"\tINTEGER NOT NULL,\n" +
"\t\"Name\"\tTEXT,\n" +
"\t\"Mean\"\tTEXT,\n" +
"\tFOREIGN KEY(\"Id\") REFERENCES \"Words\"(\"Id\"),\n" +
"\tPRIMARY KEY(\"Id\")\n" +
");");
}
public Word FindWord(DbConnection data, String kelime, SQLiteDatabase db){
Word w= null;
Cursor c = db.rawQuery("SELECT * FROM Words WHERE Name = kelime",null);
while (c.moveToNext()){
w = new Word(c.getInt(c.getColumnIndex("Id"))
,c.getString(c.getColumnIndex("Name"))
,c.getString(c.getColumnIndex("Mean")));
}
return w;
}
public Boolean ifExists (DbConnection data, String kelime, SQLiteDatabase db) {
Word w= new Word();
Cursor c = db.rawQuery("SELECT * FROM Mylist WHERE Name = kelime",null);
while (c.moveToNext()){
w = new Word(c.getInt(c.getColumnIndex("Id"))
,c.getString(c.getColumnIndex("Name"))
,c.getString(c.getColumnIndex("Mean")));
}
if(w!=null) return true;
else return false;
}
最佳答案
用
db.rawQuery("SELECT * FROM Words WHERE Name = '" + kelime + "'", null);
db.rawQuery("SELECT * FROM Mylist WHERE Name = '" + kelime + "'", null);
代替
db.rawQuery("SELECT * FROM Words WHERE Name = kelime",null);
db.rawQuery("SELECT * FROM Mylist WHERE Name = kelime",null);
关于java - 为什么SQLite没有给出这样的列错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59492893/