1
Cursor cursor = db.rawQuery("SELECT id,lastname FROM people WHERE lastname='John Kenedy'; ",null);

Is that correct usage of comparing String ? if no, How can I compare String values in the database?

1
  • you can use "=" for straight string comparisons, there's also LIKE, GLOB, REGEXP and MATCH (if you are using a free-text search table/fts3) - what is your use case? Oh, and btw, performance is improved by SQLiteStatements - not tweaking rawQuery with parameters - that just prevents injections. Commented Jun 3, 2012 at 22:59

1 Answer 1

7

For better performance, you should use rawQuery method with selectionArgs which is faster and more secure against adding directly data to statement. So try it like this

Cursor cursor = db.rawQuery("SELECT id,lastname FROM people WHERE lastname = ?; ", new String[] {"John Kenedy"});
Sign up to request clarification or add additional context in comments.

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.