gpt4 book ai didi

android - 仅查询表中的第一条数据

转载 作者:行者123 更新时间:2023-11-29 15:32:55 25 4
gpt4 key购买 nike

我试图只查询表中的第一个数据。

Cursor img_cursor = db.query(
IMAGE_URL_TABLE_NAME,
new String[]{"small_img_url" , "large_img_url"},
null",
null, null, null, null);

有人能告诉我如何实现只从表中检索第一个数据的查询吗?

解决方案

我想我解决了这个问题:

Cursor img_cursor = db.query(
IMAGE_URL_TABLE_NAME,
new String[]{"small_img_url" , "large_img_url"},
null",
null, null, null, null , "1");

我首先使用了limit 1,但是应用程序崩溃了。只有当我将数字作为 String 传递时,它才会起作用。当我们使用限制参数时,查询有 8 个参数。

最佳答案

限制 1

来自文档:

public Cursor query (boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)

因此,将您的最后一个参数设为“limit 1”。

Cursor img_cursor = db.query(
IMAGE_URL_TABLE_NAME,
new String[]{"small_img_url" , "large_img_url"},
null,
null, null, null, "limit 1");

关于android - 仅查询表中的第一条数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4190968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com