如何在下面的特定时间之后进行返回作业总数的查询是我的sqllite表我现在正在使用Java获取当前时间如何进行查询,这会在特定时间后返回我的作业总数???
private static final String TABLE_COMPLETED_JOBS = "jobs";
String CREATE_COMPLETED_TABLE = "CREATE TABLE " + TABLE_COMPLETED_JOBS
+ "(" + KEY_COMPID + " INTEGER PRIMARY KEY," + KEY_TIMEJOB
+ " TEXT," + KEY_PICK + " TEXT," + KEY_DEST + " TEXT,"
+ KEY_FARE + " TEXT,"
+ KEY_TIMEWEEK + " DateTime" + ")";
String selectQuery = "SELECT * FROM " + TABLE_COMPLETED_JOBS + " ORDER BY
"+KEY_TIMEWEEK+" ;
String mydate =
java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
答案 0 :(得分:0)
假设您编写的查询有效:
String selectQuery = "SELECT * FROM " + TABLE_COMPLETED_JOBS + " ORDER BY
"+KEY_TIMEWEEK+" ;
在执行数据库操作的databaseHandler类中,您可以使用游标来获取计数:
db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery);
int counter;
if(c != null) {
counter = c.getCount();
}
c.close();
return counter;
因此:如果counter=0
表示没有提取记录,而counter>0
表示有记录。
希望有所帮助!
答案 1 :(得分:0)
这是查询。
SELECT COUNT(*)
FROM jobs
WHERE KEY_TIMEWEEK > myDate
此处,KEY_TIMEWEEK
应为列的名称,myDate
应为yyyy-MM-dd
格式的日期。您可以像这样格式化日期:
SimpleDateFormat dbDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
String myDate = dbDateFormat.format(c.getTime);
这将以yyy-MM-dd格式返回当前系统日期
答案 2 :(得分:0)
int myCount = getData();
Handler handle = new Handler();
handle.postDelayed(new Runnable()
{
@Override
public void run()
{
"the code to be exec."
}
}, delayTimeInMilliseconds);
}
public void getData(){
db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery);
int counter;
if(c != null) {
counter = c.getCount();
}
c.close();
return counter;
}
只需在处理程序延迟时间内以毫秒为单位添加时间,即可获得所需的输出。
谢谢!