2 ciganxian ciganxian 于 2016.09.20 17:21 提问

SQLite进行记录查询时错误

List currentList = new ArrayList<>();
Cursor cursor = db.rawQuery("select name from SearchHistory order by priority", null);
while (cursor.moveToNext()) {
currentList.add(cursor.getString(0));
}

        数据库中已经有此条数据了,再进行查询时总是出现 no such column 错误,求解答

3个回答

wei242425445
wei242425445   2016.09.20 17:28

把数据表放上来看看呗

ciganxian
ciganxian db.execSQL("CREATE TABLE SearchHistory(id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,priority INTEGER)");然后在执行Cursor cursor = db.rawQuery("select * from SearchHistory where name = " + searchName, null);这句的时候就总出现 no such column的错误,但是数据库中已经存在searchName这条记录了
大约一年之前 回复
ciganxian
ciganxian   2016.09.20 17:37

db.execSQL("CREATE TABLE SearchHistory(id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,priority INTEGER)");然后在执行Cursor cursor = db.rawQuery("select * from SearchHistory where name = " + searchName, null);这句的时候就总出现 no such column的错误,但是数据库中已经存在searchName这条记录了

wei242425445
wei242425445   2016.09.20 17:43

Cursor cursor = db.rawQuery("select * from SearchHistory where name=?", searchName);

Csdn user default icon
上传中...
上传图片
插入图片