user3350995
user3350995

Reputation: 3

Unrecognized token AND

I am having problems in the next query:

This is my array of data

 String[] columns = new String[]
{ KEY_ROWELEMENTID, KEY_STUDYID,  KEY_ELEMENTCODE, KEY_ELEMENTNAME};

I create a cursor to this array where: The column KEY_ELEMENTCODE is equal to a varable result AND KEY_STUDYID is equal to a varable result AND

 Cursor c = 
ourDatabase.query(DATABASE_TABLEELEMENTS, columns,  KEY_ELEMENTCODE + "=" + elementRequest 
 + "AND" + KEY_STUDYID + 
"=" + idStudy, null, null, null, null);

What is the problem? I have debug and all variables has the correct values

Thanks

Upvotes: 0

Views: 88

Answers (4)

Tragalunas
Tragalunas

Reputation: 311

You are missing the spaces around AND.

  • " AND " +

Upvotes: 1

developer
developer

Reputation: 1625

Just try to add space before and after "AND" and write as " AND " , hope it will resolve your issue :)

Upvotes: 0

Rohit Jagtap
Rohit Jagtap

Reputation: 1670

Yes there should be space as " AND ", One more thing, if you are comparing for Integer values then use this line,

    Cursor c = ourDatabase.query(DATABASE_TABLEELEMENTS, columns,  
        KEY_ELEMENTCODE + "=" + elementRequest
                + " AND " + KEY_STUDYID +
                "=" + idStudy, null, null, null, null);

and if you are comparing string values then you should use single inverted comma as,

    Cursor c = ourDatabase.query(DATABASE_TABLEELEMENTS, columns,
        KEY_ELEMENTCODE + "=" +"'"+elementRequest+"'"+
                + " AND " + KEY_STUDYID +
                "=" + "'"+idStudy+"'", null, null, null, null);

Let me know if it works for you...

Upvotes: 0

xlecoustillier
xlecoustillier

Reputation: 16351

Without seeing the output from

KEY_ELEMENTCODE + "=" + elementRequest + "AND" + KEY_STUDYID + "=" + idStudy

I guess that you just have to replace

"AND"

with

" AND "

Upvotes: 1

Related Questions