我希望用两个条件选择sqlite数据库中的所有数据,"日期"安达"时间"。日期格式为" dd / mm / yyy或01/12 / 2014"时间是" hh:mm或17:15"。
Bellow是我的databasehandler中的代码
public List getMessageToSent(String Date,String Time){
List<TestSaving> savingList = new ArrayList<TestSaving>();
String query = "Select " + KEY_ROWID + "," + KEY_CONTACT_NAME + ","
+ KEY_CONTACT_NO + "," + KEY_CONTACT_MESSAGE + ","
+ KEY_CONTACT_PICTURE + " from testsaving where "
+ KEY_CONTACT_DATESEND + " = " + Date + " AND "
+ KEY_CONTACT_TIMESEND + " = " + Time + " order by "
+ KEY_CONTACT_NAME;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
if (cursor.moveToFirst()) {
do {
TestSaving testSave = new TestSaving();
testSave.set_contact_id(Integer.parseInt(cursor.getString(0)));
testSave.set_contact_name(cursor.getString(1));
testSave.set_contact_no(cursor.getString(2));
testSave.set_contact_message(cursor.getString(3));
testSave.set_contact_picture(cursor.getBlob(4));
savingList.add(testSave);
} while (cursor.moveToNext());
}
db.close();
return savingList;
}
和bellow是我在BroadCastReceiver Class中的代码
@Override
public void onReceive(Context context, Intent intent) {
DataBaseHandler db = new DataBaseHandler(context);
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
Date = new StringBuilder().append(Utility.utilTime(day)).append("/")
.append(Utility.utilTime(month)).append("/")
.append(Utility.utilTime(year));
Time = new StringBuilder().append(Utility.utilTime(hour)).append("/")
.append(Utility.utilTime(minute));
List<TestSaving> testSavings = db.getMessageToSent(Date.toString(),
Time.toString());
for (TestSaving ts : testSavings) {
String log = "contact_id:" + ts.get_contact_id()
+ " ,contact_name: " + ts.get_contact_name()
+ " ,contact_no: " + ts.get_contact_no()
+ " ,contact_message: " + ts.get_contact_message()
+ " ,contact_picture: " + ts.get_contact_picture();
Log.d("Result: ", log);
Notification(context, Date + " dan " + Time);
}
}
当我查看日志时,我不会收到错误。可以有人,告诉我如何解决它?
P.s接收器可以正常处理虚拟数据,