2012-07-13 1 views
2

我在android中使用sqlite,我通過傳遞多個where子句獲取結果,這給我一個錯誤。 Single where子句適用於我的問題是使用multiple where子句。 建議我修改或識別錯誤,我做的請Android的SQLite查詢與多個其中

錯誤消息的查詢

ERROR/AndroidRuntime(837): Caused by: android.database.sqlite.SQLiteException: 
no such column: Maharashtra:,while compiling: SELECT _id, r_shop FROM retailer 
WHERE r_state = Maharashtra AND r_city = Thane AND r_region = Checknaka 

String selection = MySQLiteHelper.STATE + " = Maharashtra" 
       +" AND " + MySQLiteHelper.CITY + " = Thane" 
       +" AND " + MySQLiteHelper.REGION + " = Checknaka"; 

     Cursor cursor = database.query(MySQLiteHelper.RETAILER_TABLE, 
        new String[] {MySQLiteHelper.COLUMN_ID, MySQLiteHelper.SHOP }, selection, 
        null, null, null, null); 

回答

10
String selection = MySQLiteHelper.STATE + " = 'Maharashtra'" 
      +" AND " + MySQLiteHelper.CITY + " = 'Thane'" 
      +" AND " + MySQLiteHelper.REGION + " = 'Checknaka'"; 

    Cursor cursor = database.query(MySQLiteHelper.RETAILER_TABLE, 
       new String[] {MySQLiteHelper.COLUMN_ID, MySQLiteHelper.SHOP }, selection, 
       null, null, null, null); 

可能的原因是,你是指的字符串不''

+0

-Nunu謝謝你的工作.. – Sumit 2012-07-13 07:46:37

+0

好,不要忘記接受答案:) – Nermeen 2012-07-13 07:57:28

+0

_Nunu我還有1個問題是我在where子句中傳遞的字符串也應該忽略區分大小寫。我該怎麼辦 – Sumit 2012-07-13 08:23:59