Android:Sqlite rawQuery 超出范围

发布于 2024-11-04 13:46:40 字数 610 浏览 1 评论 0原文

我正在尝试使用带有 simpleCursorAdapter 的 rawQuery 来显示到列表视图,但它一直向我抛出错误

04-29 13:36:36.453:错误/AndroidRuntime(29539):java.lang.RuntimeException:无法启动活动ComponentInfo {com.QuoteMachine / com.QuoteMachine.Quote}:android.database.sqlite.SQLiteException:绑定或列索引超出范围:句柄 0x2f65e0

我有一个名为 Quotes 的表,其中包含 _id、auth_name、quote、category 列,我的查询如下所示

return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes",
            new String[]{"WHERE auth_name = 'Robert Anton Wilson'"});

有人知道解决此问题的建议吗?我最初的计划是使用基本查询语句,但 _id 列有问题,建议我采用这种方法。

I am trying to use a rawQuery with a simpleCursorAdapter to display to a listview, but it keeps throwing me an error

04-29 13:36:36.453: ERROR/AndroidRuntime(29539): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.QuoteMachine/com.QuoteMachine.Quote}: android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x2f65e0

I have a table called Quotes with columns _id, auth_name, quote, category and my query looks as follows

return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes",
            new String[]{"WHERE auth_name = 'Robert Anton Wilson'"});

Might anyone know of a suggestion to fix this problem?My original plan was to use a basic query statement, but there was a problem with column _id and it was suggested I go with this approach.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

硪扪都還晓 2024-11-11 13:46:40

您使用 rawQuery() 错误。第二个变量用于参数,而不是用于 WHERE 子句。使用它来代替:

return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes WHERE auth_name = ?",
            new String[] { "Robert Anton Wilson" } );

Your using the rawQuery() wrong. The second variable is for the arguments, not for the WHERE clause. Use that instead:

return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes WHERE auth_name = ?",
            new String[] { "Robert Anton Wilson" } );
半透明的墙 2024-11-11 13:46:40

可能与 quote() 函数混淆?您的其中一栏称为“报价”。

http://www.sqlite.org/lang_corefunc.html

http://www.sqlite.org/lang_keywords.html

Possibly confusion with the quote() function? One of your columns is called 'quote'.

http://www.sqlite.org/lang_corefunc.html

http://www.sqlite.org/lang_keywords.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文