2

I am using sqlite in android where i am fetching result by passing multiple where clause, which gives me an error. Single where clause works fine for me problem is with multiple where clause. suggest me the changes or identify the mistake I am doing please

Error message with query

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

1 Answer 1

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

May be the reason is that, you are refering to Strings without ''

Sign up to request clarification or add additional context in comments.

4 Comments

_Nunu I have 1 more problem that is The string that i am passing in where clause should also ignore the case sensitivity. what should i do for that
That was useful for raw query what if i am not using raw query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.