Problem with logging in using sqlite

Asked

Viewed 46 times

1

My method is not returning the professor logged in.

    public Professor autenticarUsuario(String usuario, String senha) {

    String SQL = "select * from PROFESSOR where USUARIO = ? and SENHA = ? ";
    String[] selectionArgs = new String[] { usuario, senha };
    Cursor cursor = dataBase.rawQuery(SQL, selectionArgs);
    int idRow;
    Professor professor=null;

    if (cursor.getCount() > 0){
        if (cursor.moveToFirst()){
            professor = new Professor();
            idRow = cursor.getInt(cursor.getColumnIndexOrThrow("rowid"));
            professor.setCodProfessor(cursor.getString(cursor.getColumnIndexOrThrow("CODPROF")));
            professor.setNomeProfessor(cursor.getString(cursor.getColumnIndexOrThrow("NOME")));
            professor.setUsuario(cursor.getString(cursor.getColumnIndexOrThrow("USUARIO")));
            professor.setSenha(cursor.getString(cursor.getColumnIndexOrThrow("SENHA")));
        }
    }
    cursor.close();

Return professor;}

Table:

  CREATE TABLE PROFESSOR"+
                    "(CODPROF VARCHAR(10) PRIMARY KEY,"+
                    "NOME VARCHAR(40),"+
                    "USUARIO VARCHAR (60),"+
                    "SENHA VARCHAR (60));"

1 answer

1

Does not have rowid in your table. Check this row:

 idRow = cursor.getInt(cursor.getColumnIndexOrThrow("rowid"));

Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.