java - 如何从房间数据库中获取字符串
问题描述
我需要从我的房间数据库中获取一个字符串并将其设置为文本视图中的文本我在我的 dao 中使用此代码
@Query("SELECT question, question_heat, question_gender FROM questions WHERE question_heat = :heat AND question_gender = :gender" +
" ORDER BY RANDOM() LIMIT 1")
String getQuestion(int heat, int gender);
我只想从我的问题数据库中获取一个随机问题。我收到此错误:
error: Not sure how to convert a Cursor to this method's return type String getQuestion(int heat, int gender);
在构建输出中说错误在查询中
我在房间里真的很新,我使用 sqlopenhelper 有一段时间了,我真的不知道在这里做什么。
我在谷歌找到了一些代码,但它们是用于数据列表的,我只想得到一个字符串。
解决方案
您必须只选择question
列。试试这个方法:
@Query("SELECT question FROM questions WHERE question_heat = :heat AND question_gender = :gender ORDER BY RANDOM() LIMIT 1")
String getQuestion(int heat, int gender);
推荐阅读
- sql - 两个日期之间的月份 | PostgreSQL
- php - 为什么 TCPDF 在我的 PDF 中添加奇怪的顶部空间?
- html - Css:当子元素的高度小于 100% 时,将 div 元素设置为其父元素的 100%
- pip - 我正在尝试安装 rasa 并出现此错误,有人可以帮助我吗
- laravel - 如何访问控制器中的查询字符串和laravel的路由
- django - 登录根据模板中的特定组重定向到特定页面
- linux-kernel - 在执行简单驱动程序的内核 insmod 时,只创建伪 .gcda 文件和 .gcno 符号链接?如何获得正确的 *.gcda 文件?
- excel - Excel, qn 关于生成随机婚姻状况
- python - 避免在终端/cmd 上运行 FFmpeg
- python - 使用 fastText 执行示例代码时遇到问题