I need to validate a user in the database. If it is valid, I want to call the second Activity.
What method to use to do this validation in the android database?
Insertion code:
public String insereProfessor(Professor professor) {
ContentValues valores;
long resultado = 1;
dataBase = bancoDados.getWritableDatabase();
valores = new ContentValues();
valores.put("CODPROF", professor.getCodProfessor());
valores.put("NOME", professor.getNomeProfessor());
valores.put("USUARIO", professor.getUsuario());
valores.put("SENHA", professor.getSenha());
resultado = dataBase.replaceOrThrow("PROFESSOR", null, valores);
dataBase.close();
if (resultado == -1)
return "Erro de registro";
else
return "Registro Inserido com sucesso";
}
I tried to authenticate it as follows:
public Professor consutaProfessorNoBanco(String usuario, String senha) {
try {
String SQL = "select CODPROF, NOME, USUARIO, SENHA from PROFESSOR where USUARIO = ? and SENHA = ? ";
String[] selectionArgs = new String[]{usuario, senha};
Cursor cursor = dataBase.rawQuery(SQL, selectionArgs);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
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();
} catch (Exception erro) {
Log.i("Erro ocnsulta", "Erro consultar no banco");
}
return professor;
}