从sqlite数据库获取最后一行 [英] Fetching last row from sqlite database
本文介绍了从sqlite数据库获取最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从我的 SQLite 数据库中获取最后一行.到目前为止,我已经尝试过 max,sql_sequence 但似乎没有任何效果.我必须获取行值并将其分配给一个类变量.感谢任何帮助,因为我是 SQLite 和 Android 的新手.谢谢..
I am trying to fetch the last row from my SQLite database. Until now i have tried max,sql_sequence but nothing seems to work. I have to fetch the row values and assign it to a class variable. Any help is appreciated as I am new to SQLite and Android. Thanks..
推荐答案
如果你已经得到了 cursor
,那么你可以通过这种方式从 cursor
获取最后一条记录>:
If you have already got the cursor
, then this is how you may get the last record from cursor
:
cursor.moveToPosition(cursor.getCount() - 1);
然后使用cursor
读取值
或
这样做
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToLast();
或
SELECT * FROM TABLE WHERE ID = (SELECT MAX(ID) FROM TABLE);
这篇关于从sqlite数据库获取最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文