java Android SQLite Query 和使用游标处理多行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3110868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:25:21  来源:igfitidea点击:

Android SQLite Query and using cursor to deal with multiple rows

javaandroidsqlitecursor

提问by Skizit

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

我有一个查询,(我正在使用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?

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

Thanks,

谢谢,

回答by Matty F

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);
  ...
}