Co Koder
Co Koder

Reputation: 2221

Android sqlite query for string

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?

Upvotes: 1

Views: 9069

Answers (1)

Simon Dorociak
Simon Dorociak

Reputation: 33495

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

Upvotes: 7

Related Questions