Reputation: 352
I've been learning Java, using Eclipse for Android, for 2 months and have just started learning about Databases. I know I am doing something wrong here and the answer is simple but I just can't get it. And I know this type of question has been asked 1M times before. Sorry to ask it again.
I have a table called TABLE_NAME:
|-----|-------|-------|
|._id.|.ITEM..|.LAST..|
|..1..|...A...|.......|
|..2..|...B...|...L...|<--I want the cursor to point to this row which has "L" in column LAST
|..3..|...C...|.......|
|-----|-------|-------|
I want the cursor to point to the row with the "L" in the "LAST" column. I am using the following code:
cursor = db.rawQuery("SELECT * FROM " +TABLE_NAME +" WHERE "+LAST+" LIKE '%"L"%'", null);
but I get a red line under the last bit of my code. Can anyone help?
Just figured out how to answer my own question:
Thanks everyone for the help. After changing '%"L"%'" to '%L%'" the new code is:
cursor = db.rawQuery("SELECT * FROM " +TABLE_NAME +" WHERE "+LAST+" LIKE '%L%'", null);
The I wrote: cursor.moveToFirst();<--- telling the cursor to go to the row the query found and then:
THESTRING =cursor.getString(cursor.getColumnIndex(LAST));<--- getting the info in the row
Thanks again everyone.
Upvotes: 0
Views: 1066
Reputation: 15701
|..2..|...B...|...L...|<--I want the cursor to point to this row which has "L" i
it should be
cursor = db.rawQuery("SELECT * FROM " +TABLE_NAME +" WHERE "+LAST+" LIKE '%L%'", null);
Upvotes: 0
Reputation: 42040
There's syntactically this error:
cursor = db.rawQuery("SELECT * FROM " +TABLE_NAME +" WHERE "+LAST+" LIKE '%"+L+"%'", null);
You are missing two +
for concatenation.
Or like this if L is an actual value not a variable
cursor = db.rawQuery("SELECT * FROM " +TABLE_NAME +" WHERE "+LAST+" LIKE '%L%'", null);
Upvotes: 0
Reputation: 5177
try this: you forget the +
db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + LAST + " LIKE '%" + L + "%'", null);
Upvotes: 0
Reputation: 15973
It should be:
cursor = db.rawQuery("SELECT * FROM " +TABLE_NAME +" WHERE "+LAST+" LIKE '%"+L+"%'", null);
with the + around L variable..
Upvotes: 0