安卓sqlite3的查询只有一个数据(第一批)从表 [英] android sqlite3 query only one data(the first) from the table

查看:97
本文介绍了安卓sqlite3的查询只有一个数据(第一批)从表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从数据库中查询只有一个数据(第一个)。

i'm trying to query only one data(the first one) from the database.

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

可能有人告诉我如何落实,查询只有一个数据(第一个),从表?

could somebody tell me how to implement , query only one data(the first one) from table?

=============================================== ===========================================

==========================================================================================

感谢您,xandy〜

我解决了这个问题,但我认为答案是:

I solved the problem , but i think the answer is :

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

我用限制1 在第一时间,但坠毁,如果只通过数字作为字符串,它工作原理。

I used limit 1 at the first time , but crashed , if only pass number as a String , it works.

顺便说一句,查询有8个参数,而我们使用的限制参数。 THX所有

by the way , query has 8 parameters while we using the limit parameter. thx all

推荐答案

限制1

从技术文档:

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

所以,把你的最后一个参数是限制1。

so, put your last argument to be "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");

这篇关于安卓sqlite3的查询只有一个数据(第一批)从表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆