rawQuery() 游标上对字段槽 0,1 的错误请求
我对 android 还很陌生,我遇到了以下问题。 这是我的代码,我试图将数据库中的数据获取到我的列表中。
private List<Model> getModel(int a) {
dbHelper = new DbHelper(this);
db = dbHelper.getWritableDatabase();
Log.d("Model Int: ", "Model int: " + a);
sql = "SELECT * FROM shows";
resultCursor = db.rawQuery(sql, new String [] {});
resultCursor.moveToFirst();
List<Model> list = new ArrayList<Model>();
list.add(get(Html.fromHtml(resultCursor.getString(a)).toString()));
for (resultCursor.moveToFirst(); resultCursor.moveToNext(); resultCursor
.isAfterLast()) {
list.add(get(Html.fromHtml(resultCursor.getString(a))
.toString()));
}
startManagingCursor(resultCursor);
resultCursor.close();
db.close();
dbHelper.close();
return list;
}
效果很好,但是当我不想使用 * 而是使用
sql = "SELECT title subtitle FROM Shows";
来获取所有列时。我收到这样的错误
错误/CursorWindow(371):字段槽 0,1 的请求错误。行数 = 162、列数 = 1
知道出了什么问题吗?
提前致谢。
I am pretty new to android, and I have the following problem.
This is my code where I'm trying to get data from the database into my list.
private List<Model> getModel(int a) {
dbHelper = new DbHelper(this);
db = dbHelper.getWritableDatabase();
Log.d("Model Int: ", "Model int: " + a);
sql = "SELECT * FROM shows";
resultCursor = db.rawQuery(sql, new String [] {});
resultCursor.moveToFirst();
List<Model> list = new ArrayList<Model>();
list.add(get(Html.fromHtml(resultCursor.getString(a)).toString()));
for (resultCursor.moveToFirst(); resultCursor.moveToNext(); resultCursor
.isAfterLast()) {
list.add(get(Html.fromHtml(resultCursor.getString(a))
.toString()));
}
startManagingCursor(resultCursor);
resultCursor.close();
db.close();
dbHelper.close();
return list;
}
that works fine, but when i do not want to get all the columns with * but with
sql = "SELECT title subtitle FROM shows";
instead. I get errors like this
ERROR/CursorWindow(371): Bad request for field slot 0,1. numRows =
162, numColumns = 1
Any ideas what's going wrong?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
真正的意思
是:仅选择一列:
title
,但在结果集中将该列重命名为“subtitle”。这称为为列分配
别名
。请参阅:http://beginner-sql-tutorial.com/sql-aliases.htm
解决方案
执行:
现在您正在选择两列。
免责声明
我不保证该链接中信息的质量,网上有很多质量较差的
教程
。我刚刚查看了“别名”部分,该部分看起来很有用。Really means
In english: select only one column:
title
, but rename that column to "subtitle" in the resultset.This is called assigning an
alias
to a column.See: http://beginner-sql-tutorial.com/sql-aliases.htm
Solution
Do:
Now you are selecting two columns.
Disclaimer
I do not vouch for the quality of the info in that link, there are a lot of poor quality
tutorials
on the net. I just looked at the "alias" section and that section looks useful.我没有完全理解你的问题,但我认为你需要特定的字段,然后
定义用逗号分隔的字段
I didn't perfectly understand your question but I think u need specific field then
define the fields seperated by commas