关于在sqlite数据库中显示最后一条记录的建议

时间:2017-04-18 00:42:49

标签: java android sqlite

我想显示数据库中的最后一条记录

var payload = { 
    username: 'test',
    password: 'test'
    };

 var url = "https://MYWEBSITE.com/rest_login/user/token.json";

 var client = Ti.Network.createHTTPClient({
     // function called when the response data is available
     onload : function(e) {
         Ti.API.info("Received text: " + this.responseText);
         alert('success');
     },
     // function called when an error occurs, including a timeout
     onerror : function(e) {
         Ti.API.error(e.error);
         alert('error');
     },
     timeout : 5000  // in milliseconds
 });
 // Prepare the connection.
 client.open("POST", url);
 client.setRequestHeader('Content-Type', 'application/json');
 // Send the request.
 client.send(payload);

此代码显示所有记录。我该怎么做只显示最后一个条目?

1 个答案:

答案 0 :(得分:0)

您可以在sql中使用limit关键字:

Cursor cur = db.rawQuery("SELECT * FROM " + TABLE_NAME + " ORDER BY table_idx DESC LIMIT 1", null);