我想從最近1周的數據庫獲取記錄。我將當前日期和日期前7天,我將它們發送到數據庫處理程序,但它返回錯誤:如何發送日期作爲參數從數據庫中獲取記錄
The method `getALLCompJobs(String, String)` in the type `DatabaseHandler` is not applicable for
the `arguments (Date, Date)`
以下是我的代碼。請幫助我弄清楚如何從數據庫獲取過去一週的記錄。
public class JobSchema extends BackBaseActivity {
Date dateBefore7day;
Date CurrentDate;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.jobsschema);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm");
df.format(c.getTime());
CurrentDate=c.getTime();
c.add(Calendar.DAY_OF_MONTH, -7);
dateBefore7day= c.getTime();
DatabaseHandler db = new DatabaseHandler(JobSchema.this);
jobarr = db.getALLCompJobs(CurrentDate,dateBefore7day);
<---error show The method getALLCompJobs(String, String) in the type
DatabaseHandler is not applicable for the arguments (Date, Date) --?
public class DatabaseHandler extends SQLiteOpenHelper {
String CREATE_COMPLETED_TABLE = "CREATE TABLE " + TABLE_COMPLETED_JOBS
+ "(" + KEY_COMPID + " INTEGER PRIMARY KEY," + KEY_TIMEJOB
+ " TEXT," + KEY_TIMEWEEK+ " DATE," + KEY_PICK + "
TEXT," + KEY_DEST + " TEXT,"
+ KEY_FARE + " TEXT" + ")";
public List<JobSchmeModel> getALLCompJobs(String CurrentDate, String
dateBefore7day) {
//public List<JobSchmeModel> getALLCompJobs() {
List<JobSchmeModel> compjobsList = new ArrayList<JobSchmeModel>();
String selectQuery = "SELECT * FROM " + TABLE_COMPLETED_JOBS + " WHERE "
+ KEY_TIMEWEEK + ">=" + dateBefore7day + " AND " + KEY_TIMEJOB + "<=" +
CurrentDate + " ORDER BY "+KEY_COMPID+" DESC";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
你需要傳遞日期在'getALLCompJobs(..)'字符串。 –
和我將如何從數據庫recoreds?如果我將日期作爲字符串傳遞,它將從數據庫中獲取記錄? – user3332060
是的,但請確保您的日期字段的數據類型爲「DATETIME」,因爲我上次告訴您,如果您還記得。 –