How do I know if the cpf field does not exist in the database?

0

Example of what I'm trying to do:

    vRS = sql.executeQuery();
     while(vRS.next())
     {
         nome = vRS.getString("nome");
         cargo = vRS.getString("cargo");
     }

What I want to do is when the registry does not exist to display a message from System.out.Println ("It does not exist in the database!");

        if (!vRS.next()) {
            System.out.println("Não Encontrou cpf ou cnpj");
             setVerMensagem(true);
             setVerGrid(false);
        } 

This form bugs what would be the correct way?

    
asked by anonymous 21.10.2016 / 18:17

1 answer

2

As you have not left too many details of what you are trying to do, I will leave the code below to test

vRS = sql.executeQuery();
if (vRS != null) {
  while (vRS.next()) {
   nome = vRS.getString("nome");
   cargo = vRS.getString("cargo");
  }
} 
else {
  System.out.println("Não Encontrou cpf ou cnpj");
  setVerMensagem(true);
  setVerGrid(false);
}
    
21.10.2016 / 21:09