0
I need to return a user’s name in an SQLITE query: I’m using the following code:
public String verificarUsuario(String login)
{
try
{
String selectQuery = "select nome from usuarios where login = " + login;
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToFirst();
String nomeString = cursor.getString(cursor.getColumnIndex("tipoFunc"));
StringBuilder conversor = new StringBuilder();
conversor.append(nomeString);
return conversor.toString();
}
But the following error is appearing:
no such column: lgomes (code 1): , while compiling: select name from usuarios Where login=lgomes
Thanks!! It worked, now it worked
java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
– Lucas Charles
@Lucascharles this error is because you have to put the correct index:
String nomeString = cursor.getString(cursor.getColumnIndex("nome"))
– viana
Well, there’s another problem, @Lucascharles I think you should open a new question, with this information and the stacktrace of error.
– Jéf Bueno
@Lucascharles cursor.getColumnIndex("name")
– viana
@acklay Thank you so much
– Lucas Charles