Skip to content Skip to sidebar Skip to footer

Syntax Error When Querying Contacts Database For An Email

I am trying to do a search through the contacts database for an email address and get the contact ID of that person if it finds it but everytime I try I get a syntax error 01-03 17

Solution 1:

Try putting quotes around your email, ie, change the third parameter in your method call to

Data.DATA1  + "='" + from + "'"

Solution 2:

elijah answer: Data.DATA1 + "='" + from + "'" ... well ... works (hehe)

question ... what if from contains ''' ?

for this question(and as better/generic answer) we can use:

Cursor contact = context.getContentResolver().query(Data.CONTENT_URI,new String[]{Data.RAW_CONTACT_ID},Data.DATA1 + "=?",new String[]{from},null);

selection = Data.DATA1 + "=?" and selectionArgs = new String[]{from}(instead null)

Post a Comment for "Syntax Error When Querying Contacts Database For An Email"