Android原始查询问题

时间:2011-08-23 10:57:07

标签: android

我有一个数据库,其中有一列以毫秒为单位的日期。我正在尝试执行一个查询,它允许我只检索大于当前系统时间的日期,并按升序排列。

这就是我所做的,但它似乎没有用,帮助会非常感激。

    long lowestDate = 0;
    long currentTime = System.currentTimeMillis(); 
    String CT = Long.toString(currentTime);
    String[] args = {CT};
    mDb = mDbHelper.getReadableDatabase();
    String mySQL =   " select dt" 
                   + " from reminders"
                   + " where dt > " + args[0]
                   + " orderby dt Asc ";
    Cursor c1 = mDb.rawQuery(mySQL, null);

3 个答案:

答案 0 :(得分:2)

String mySQL =   " select dt" 
                   + " from reminders"
                   + " where dt > " + System.currentTimeMillis()
                   + " order by dt Asc ";

“排序依据”而不是“orderby”,长串拼接是自动的。

答案 1 :(得分:1)

 long lowestDate = 0;
    long currentTime = System.currentTimeMillis(); 
    String CT = Long.toString(currentTime);
    String[] args = {CT};
    mDb = mDbHelper.getReadableDatabase();
    String mySQL =   " select dt" 
                   + " from reminders"
                   + " where dt > '" + args[0]
                   + "' orderby dt Asc ";
    Cursor c1 = mDb.rawQuery(mySQL, null);

试试这个

答案 2 :(得分:0)

尝试

 String mySQL =   "select dt" 
                       + " from reminders"
                       + " where dt > '" + args[0]
                       + "' orderby dt Asc";