Android SQLite 查询并使用游标处理多行

发布于 2024-09-06 20:49:10 字数 241 浏览 0 评论 0原文

我有一个查询(我正在使用 rawQuery()),

  SELECT * FROM <table>

然后我使用游标存储它返回的内容。从他们看来,我想做的是,从第一行开始,所以..cursor.moveToFirst()然后逐列获取每一列并将其特定值存储在变量中。然后我想移动到下一行并执行相同的操作。所以我想我的问题是如何让光标处理多列?

谢谢,

I've got a query, (I'm using rawQuery())

  SELECT * FROM <table>

I'm then storing what it returns using a cursor. From their what I want to do is, start at the first row so.. cursor.moveToFirst() then take each column , column by column and store its particular value in a variable. I then want to move onto the next row and do the same. So I guess my question is How would I get cursor to deal with multiple columns?

Thanks,

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

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

发布评论

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

评论(1

人海汹涌 2024-09-13 20:49:10

我可能在这里遗漏了一些东西,难道你没有嵌套循环吗?

外循环循环遍历每条记录:

while (cursor.moveToNext()) {
  ...
  // inner loop here
  ...
}

内循环循环遍历每一列

for (i=0; i<cursor.getColumnCount(); i++) {
  ...
  String var1 = cursor.getString(i);
  ...
}

I might be missing something here, wouldn't you have a nested loop.

The outer loop cycles through each records:

while (cursor.moveToNext()) {
  ...
  // inner loop here
  ...
}

and the inner loop would cycle through each column

for (i=0; i<cursor.getColumnCount(); i++) {
  ...
  String var1 = cursor.getString(i);
  ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文