0
How can I check if a login has already been registered? Below is an excerpt from an attempt I made. If you can help me thank you.
This is an excerpt from the DAO layer.
public boolean validarLogin () throws SQLException, ClassNotFoundException {
String login = null;
this.conn=new ConnectionFactory().getConnectionFactory();
boolean testa;
String LOGIN_SQL ="SELECT login FROM pessoa WHERE login = ?";
PreparedStatement st = conn.prepareStatement(LOGIN_SQL);
st.setString(1, login);
ResultSet rs = st.executeQuery();
if (rs.next()){
testa = rs.getBoolean(LOGIN_SQL);
}
else {
testa = false;
}
return testa;
}
Here is the code that appears in the VIEW event.
PessoaDAO pDAO = new PessoaDAO();
boolean login = false;
try {
login = pDAO.validarLogin();
} catch (SQLException ex) {
Logger.getLogger(cadastrar_pessoa.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(cadastrar_pessoa.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(login);
I am studying on my own and am having some beginner problems, as you can see. (rs)
https://answall.com/questions/276585/howto checkout%C3%A1rio-j%C3%A1-was-registered-in-database
– Valdeir Psr
It is necessary to pass a parameter to
validarLogin
. Ex:public boolean(String login)
; Then removeString login = null
and finallypDAO.validarLogin("seu-login");
– Valdeir Psr
It worked perfectly. I appreciate the help.
– elbenevides