开发者

SQLiteException no such column

I am writing 开发者_运维知识库an SQL query like this:

Cursor data = db.query(WhereWolfOpenHelper.FRIEND_TABLE_NAME, null, WhereWolfOpenHelper.FRIEND_GROUP_COLUMN+"="+params[0], null, null, null, null);

And it's producing the following error:

ERROR/AndroidRuntime(620): Caused by: android.database.sqlite.SQLiteException: no such column: Friends: , while compiling: SELECT * FROM ww_friend WHERE friend_group=Friends

There is no column called Friends, I want to retrieve the rows where the friend_group column has the value Friends. What am I doing wrong?


you need to surround Friend value with quote :

Cursor data = db.query(WhereWolfOpenHelper.FRIEND_TABLE_NAME, null, WhereWolfOpenHelper.FRIEND_GROUP_COLUMN+"='"+params[0]+"'", null, null, null, null);

PS: be sure to escape dangerous characters from param[0] when you do like this to avoid SQL Injection


I'm guessing that "Friends" is a value, so you must enclose it within quotes.

Try this:

Cursor data = db.query(WhereWolfOpenHelper.FRIEND_TABLE_NAME, null, WhereWolfOpenHelper.FRIEND_GROUP_COLUMN+"=\""+params[0]+"\"", null, null, null, null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜