开发者

Query only the first data from a table

I'm trying to query only the first data from the table.

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 a query where only the first data is retrieved from a table?

Solution

I think I solved the answer:

Cursor img_cursor = db.query(
               开发者_开发百科     IMAGE_URL_TABLE_NAME,
                    new String[]{"small_img_url" , "large_img_url"},
                    null",
                    null, null, null, null , "1");

I used limit 1 first, but the application crashed. Only if I pass the number as a String will it work. The query has 8 parameters while we're using the limit parameter.


limit 1

From Documentation:

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

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜