Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

406
Visualizações
rs.next() returns false in java

the code is login there are entries in my database my also query is working fine but whenever i put any data valid or invalid it just shows email or pass incorrect my rs.next() just returns false. I also verified jdbc connection it works fine. Used mySql databse.

package bean;
import java.sql.*;
public class LoginDao {

public static boolean validate(LoginBean bean){
    boolean status=false;
    try{
        Connection con=ConnectionProvider.getCon();

        PreparedStatement ps=con.prepareStatement("select * from user432 where email=? and pass=?");
        ps.setString(1,bean.getEmail());
        ps.setString(2, bean.getPass());

        ResultSet rs=ps.executeQuery();
        status=rs.next();

    }catch(Exception e){}
    return status;
}
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

What it looks like to me is that all this method is meant to do is validate the actual existence of a particular User which contains the supplied E-Mail address and Password. Fair enough but you claim that you always get returned false from the method. The obvious reason for that would be the fact that your query found no results otherwise rs.next() would be true.

Well, it could be the extra curly bracket at the end of your method but let's just assume you just goofed there when copy/pasting the code into your post.

It could however be that bean.getEmail() and bean.getPass() are not supplying what you think it is, I don't know since we can't see the bean class. Maybe what you should try is bean.getEmail().toString() and bean.getPass().toString().

If your code is producing an actual Exception then you're hiding it by maintaining a empty catch block. There's a real good chance that an exception of some sort is thrown and therefore providing a false result from your method but you'll never know what it is since you have nothing in place to view it. You should really have the exception as a SQLException rather than just Exception but hey, that's not the end of the world, and within the catch block you should at least put something, maybe: System.out.println("What the....sumthin wrong with ma code!!!"); or even better yet: e.printStackTrace();.

Curious...is the Database Table name really user432? Or is that a User Name?

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda