Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rawQuery: bind or column index out of range

I am trying to get user by his name like that:

public Cursor GetUser(String username)
{
    return m_dataBase.rawQuery("SELECT * FROM users WHERE name = \' ? \'", new String[] { username });
}

But then I got an exception "bind or column index out of range". What is wrong in my code?

like image 387
user1745470 Avatar asked Oct 14 '12 22:10

user1745470


1 Answers

You are trying to use a parameter, but such parameters never need to be quoted. Your query actually searches for a user named "?" (with spaces).

Just use "SELECT * FROM users WHERE name = ?".

like image 99
CL. Avatar answered Nov 11 '22 17:11

CL.