5
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);  

我想要所有同时满足条件但通过错误的记录。请帮我摆脱困境...

日志猫错误............

> 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
4

2 回答 2

12

在 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以解决剩余问题。

于 2012-12-17T06:30:21.243 回答
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;
    }
于 2017-06-10T15:52:03.117 回答