2012-12-17 42 views
3
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幫我出COM部份 日Thnx的...android中的多個where子句

日誌貓錯誤........

> 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

同樣的錯誤被repetd,reminder_id應該匹配summaryid和reminder_date應符合currentdate1 – pitambar

+0

放空間1之間「與」和提醒 –

回答

9

把周圍的一些空間,並添加這些「'」後,各地=:

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清理其餘的問題。

+0

Car_ID =「= '「通過錯誤 – pitambar

+0

是的,它應該是Car_ID +」='「+ summaryid +」AND?「。對不起,迷霧。我沒有清除所有問題,所以我給了鏈接。 –

+1

嘿thnx爲它的鏈接它wrkng – pitambar

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; 
    }