Android:如何在数据库中使用游标?

发布于 2024-12-20 15:39:57 字数 235 浏览 2 评论 0原文

我正在尝试使用光标从记录中返回字段名称。下面的语句是否返回一个表的所有记录?

Cursor u = db.query(t1, new String[] { "id","titlee","date", "tme", "detail","selcal","partmail","stat","prior"  },null, null, null, null, null);

非常感谢任何帮助。

I'm trying to return a field name from a record using cursor. Does the statement as follows returns all the records of a table?

Cursor u = db.query(t1, new String[] { "id","titlee","date", "tme", "detail","selcal","partmail","stat","prior"  },null, null, null, null, null);

Any help is highly appreciated.

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

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

发布评论

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

评论(2

大海や 2024-12-27 15:39:57
Cursor cursor = db.query(t1, new String[] { "id","titlee","date", "tme", "detail","selcal","partmail","stat","prior"},null, null, null, null, null);

Cursor cursor = db.query(t1,null ,null, null, null, null, null);

两者相同。

更新

这个答案很好地解释了如何使用where或选择查询。

Cursor cursor = db.query(t1, new String[] { "id","titlee","date", "tme", "detail","selcal","partmail","stat","prior"},null, null, null, null, null);

or

Cursor cursor = db.query(t1,null ,null, null, null, null, null);

Both are same.

UPDATE

This answer explains nicely how you can use the where or selection query.

从此见与不见 2024-12-27 15:39:57

由于没有 WHERE 子句,因此将返回所有行。游标的每个项目将准确包含您在数组中列出的字段(假设这些列存在于表中)。但是,如果您只对一个字段感兴趣(您说“字段名称”),那么您最好在查询中仅包含该列 ID。因此,假设您只真正关心“titlee”列,那么您的查询可能是:

Cursor u = db.query(t1, new String[] { "titlee" }, null, null, null, null,空);

As you have no WHERE clause, all rows will be returned. Each item of the cursor will contain exactly those fields you list in the array (assuming those columns exist in the table). However, if you are only interested in one field (you say "a field name") then you'd be better including only that column id in the query. So, assuming you only really care about the column "titlee", then your query could be:

Cursor u = db.query(t1, new String[] { "titlee" }, null, null, null, null, null);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文