android - SQLite 中的 Where 子句在 android :( 中不起作用

标签 android sqlite

尝试在 SQLite 中查询某些数据时遇到恼人的错误。

这是我的代码:

Cursor cursor= db.query(TABLE_IMAGES, new String[]{"_id"}, "name" +" = "+compareToThis, null, null, null, null);

我只是将光标作为字符串返回。

错误是说:

no such column: compareToThis: while compiling.....the statement

我的问题是:为什么 SQLite 将 compareToThis 属性设置为一个列,而它只是一个值?

我该如何解决这个问题?

提前致谢。

最佳答案

Cursor cursor= db.query(TABLE_IMAGES, new String[]{"_id"}, "name" +" = ?", new String[]{compareToThis},  null, null, null);

选择必须包括参数的占位符,下一个参数应该是参数数组。

关于android - SQLite 中的 Where 子句在 android :( 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4267409/

相关文章:

android - 如何使用Soundpool一键播放和停止声音

php - 使用索引创建表时出现 SQLite 错误

android - 使用 AbstractThreadedSyncAdapter 同步 Android 数据库 : onPerformSync isn't called

android - liveData builder 功能解决了什么问题?

android - 如何将arraylist存储在ormlite数据库中

android - NetworkType.UNMETERED 与 NetworkType.METERED - PeriodicWork

javascript - SQLITE_ERROR : no such table in Node. js

sqlite - SQLite:如何使用alter将主键添加到表?

sqlite - 如何在 pycharm 中查看 sqlite 数据库的架构?

Android线程池在后台状态后没有执行就建立了runnables