2014-03-24 65 views
0

如何在下面的特定時間之後返回總作業數的查詢是我的sqllite表我現在正在使用Java獲取當前時間如何查詢哪個返回的總數在特定時間之後工作?select查詢在特定時間之後返回的作業數

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

select count(*)或select查詢會返回一個結果集,返回的行數count cud給你count –

+0

給我舉例查詢plz – user3416078

回答

0

假設查詢你寫的作品:

String selectQuery = "SELECT * FROM " + TABLE_COMPLETED_JOBS + " ORDER BY 
     "+KEY_TIMEWEEK+" ; 

在數據庫處理器類,你執行數據庫操作,你可以使用光標獲得像計數:

db = this.getReadableDatabase(); 
Cursor c = db.rawQuery(selectQuery); 
int counter; 

if(c != null) { 
    counter = c.getCount(); 
} 

c.close(); 
return counter; 

因此:如果counter=0表示沒有記錄被提取,並且如果counter>0表示有記錄。

希望有幫助!

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當前系統日期

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; 


} 

只是在處理米利斯加入時間延遲時間你會得到所需的輸出。

謝謝!

相關問題