【发布时间】:2018-04-24 16:54:20
【问题描述】:
我必须从表中获取所有记录数。我的方法如下:
public int getTasksByStatusIDBetweenDates(int statusID, String startDate, String endDate) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(
"select * from Task" +
" where StatusID=" + statusID + " and AssignDate between '" + startDate + "' and '" + endDate + "'", null);
int total = 0;
if (cursor.moveToFirst())
total = cursor.getInt(0);
cursor.close();
return total;
}
目前它返回我 0。我的日期格式是 "yyyy-MM-dd HH:mm:ss"
请指导我哪里做错了。谢谢!
【问题讨论】:
-
你在哪里调用这个方法?你能发布我提到的代码吗?
-
@noman-hamid : 存储在您的数据库中的日期格式是否与您争论的日期格式相同 startDate 和 endDate ???
-
@AntónioPaulo 我只是在我的活动中从该函数中获取计数和整数变量。但是我从这个查询中得到的计数是 0。
-
cursor.getInt(0),你要获取表格的第一列值吗?? -
我猜你应该用
datetime()函数包装时间字符串变量