2

What is wrong with the following code? I get the following error

unrecognized token: "12345" (code 1): , while compiling: SELECT id, flag FROM myTable WHERE snumber=12345

String number = "12345";    
public static final String SNUMBER = "snumber";
public static final String ID = "id";
public static final  String FLAG = "flag";

String[] thecolumns = new String[] { ID, FLAG };

Cursor cursor = sqlDb.query(TABLE_NAME , thecolumns, SNUMBER+ "=" + number, null, null,   null, null);
2
  • Please format errors as code, rather than bolding, and give us an MCVE so we can understand what you're doing. Commented Feb 6, 2015 at 17:01
  • You've got minimal part covered. It's a simple value quoting problem, no need to include a whole android app in the post. Commented Feb 6, 2015 at 17:15

2 Answers 2

1

This should work

Cursor cursor = sqlDb.query(TABLE_NAME , thecolumns, SNUMBER+ "='" + number+"', null, null,   null, null);

I added '' around number

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

1 Comment

Thanks worked .. never knew that there was a quote over there.
0

You should escape your data. using "?" for params is great. And you need to cast it to a String. Common way doing this when not using rawQuery is:

  Cursor cursor = sqlDb.query(TABLE_NAME , thecolumns, SNUMBER+ "=?", Integer.toString(number), null,   null, null);

Comments

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.