How to know if the Cpf field does not exist in the database?

Asked

Viewed 156 times

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 record does not exist to display a message from System.out.Println("Does not exist in the bank!");

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

This way works bugada which would be the correct form?

  • How is the table with this field? Why not check whether the field is null or empty?

  • Type I want to validate Cpf with java, if the Cpf field does not exist in the base is to show an error message.

  • Like this Cpf comes from the screen.

  • And the query in the Czech method if this Cpf exists

  • Where is this data coming from? This RS variable is a vector?

  • Add more information to the question, such as the schema of this table, and how you retrieve the data from this table before checking if the field does not exist.

  • vrs is the resulSet data coming from the database.

  • but does the table contain or not the Cpf/cnpf field? So it is interesting to show the schema of which table you want to check this information.

  • has the yes field. I want to know if there is a record for the field with id.

Show 4 more comments

1 answer

2


Since you haven’t left many details of what you’re trying to do, I’ll 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);
}

Browser other questions tagged

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