String slctsummary = "select Reminder_Id,Reminder_Type,Reminder_Date,Reminder_Time,Reminder_Alert from Reminder_Main where Car_ID="
+summaryid
+"AND"
+Reminder_Date
+"="
+currentdate1;
Cursor c = sdb.rawQuery(slctsummary,null);
我希望所有记录都能满足这两个条件但通过错误。 PLZ帮助我解决这个问题 日Thnx ...
日志猫错误........
> 12-17 11:48:05.250: E/AndroidRuntime(1245):
> java.lang.RuntimeException: Unable to start activity
>ComponentInfo{com.curious.solutions.finalautoistdiary/com.curious.solutions.finalautoistdiary.ReminderSummary}:
> android.database.sqlite.SQLiteException: unrecognized token:
> "1ANDReminder_Date17": , while compiling: select
> Reminder_Id,Reminder_Type,Reminder_Date,Reminder_Time,Reminder_Alert
> from Reminder_Main where Car_ID=1ANDReminder_Date17-NOV-2012
答案 0 :(得分:9)
在AND周围添加一些空格并添加这些"'"在=:
之后String Reminder_Main="Reminder_Main",Car_ID="Car_ID",Reminder_Date="Reminder_Date";
Cursor c = sdb.rawQuery("select Reminder_Id ,Reminder_Type,Reminder_Date,Reminder_Time,Reminder_Alert from " + Reminder_Main
+" where " + Car_ID + " = ? AND " + Reminder_Date + " = ? " , new String[] { summaryid,currentdate1});
c.moveToFirst();
c.moveToFirst();
int summarycount = c.getCount();
如果这还不足以解决问题,请参阅此处https://stackoverflow.com/a/9061437/1503155以解决剩余问题。
答案 1 :(得分:0)
这是我的尝试你只关注whereClause
public List<ModelGps> gellTripByName(String tripName) {
List<ModelGps> gpses = new ArrayList<>();
SQLiteDatabase database = dbHelper.getReadableDatabase();
final String columNames[] = {DBHelper.COLUMN_ID, DBHelper.COLUMN_NAME, DBHelper.COLUMN_LATITUTE, DBHelper.COLUMN_LONGITUDE, DBHelper.COLUMN_ALTITUDE, DBHelper.COLUMN_DATE, DBHelper.COLUMN_TYPE, DBHelper.COLUMN_TRAVEL, DBHelper.COLUMN_SPEED};
String whereClause = DBHelper.COLUMN_TYPE + " = ? AND " + DBHelper.COLUMN_NAME + " = ? ";
String[] whereArgs = {"Trip", tripName};
Cursor cursor = database.query(DBHelper.TABLE_NAME_GPS, columNames, whereClause, whereArgs, null, null, DBHelper.COLUMN_NAME + " ASC");
while (cursor.moveToNext()) {
ModelGps gps = new ModelGps();
gps.setId(cursor.getLong(cursor.getColumnIndex(DBHelper.COLUMN_ID)));
gps.setName(cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_NAME)));
gps.setLatitude(cursor.getDouble(cursor.getColumnIndex(DBHelper.COLUMN_LATITUTE)));
gps.setLongitude(cursor.getDouble(cursor.getColumnIndex(DBHelper.COLUMN_LONGITUDE)));
gps.setAltitude(cursor.getDouble(cursor.getColumnIndex(DBHelper.COLUMN_ALTITUDE)));
gps.setDate(cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_DATE)));
gps.setType(cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_TYPE)));
gps.setTravel(cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_TRAVEL)));
gps.setSpeed(cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_SPEED)));
gpses.add(gps);
}
database.close();
cursor.close();
return gpses;
}