选择从sqlite订购的数据

时间:2015-04-28 00:27:58

标签: android android-sqlite

我正在尝试通过列排序获取数据,但它无法正常工作。有什么想法吗?

public ArrayList<HashMap<String, String>> getMonthData(String month,String year, String name){
    ArrayList<HashMap<String,String>> activityArrayList = new ArrayList<HashMap<String,String>>();
    String selectQuery = "SELECT * FROM activity WHERE year='"+year+"' AND month='"+month+"' AND name=? ORDER BY day ASC";
    SQLiteDatabase database = this.getWritableDatabase();
    Cursor cursor = database.rawQuery(selectQuery,new String[] { name });
    if(cursor.moveToFirst()){
        do{
            HashMap<String, String> activityMap = new HashMap<String,String>();
            activityMap.put("day",cursor.getString(2).toString());

            activityArrayList.add(activityMap);
        }while(cursor.moveToNext());
    }
    return  activityArrayList;
}

1 个答案:

答案 0 :(得分:0)

解决方案是我将日期存储为TEXT,因此它是订单词典。所以我必须把它变成真实的。使用“CAST(day AS REAL)”。