Olá pessoal,
Estou com um problema bem esquisito, nunca vi antes.
É o seguinte, tenho um programa que cadastra alunos e salva os dados em banco de dados. Está funcionando tudo certinho.
O problema é quando eu tento remover ou procurar por nome.
Se eu digitar o nome corretamente ou o primeiro nome, ele encontra normalmente, porém quando eu digito algo errado, ele deveria informar que o nome foi digitado incorretamente ou o aluno nao está cadastrado, mas ele nao informa nada e vai para o menu novamente.
Vou postar a parte do código de pesquisa por nome pra vcs me ajudarem com isso e ver oq ta acontecendo.
public void searchDataBase(String student) throws Exception
{
try
{
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/cadastro?"
+ "user=cledarsie&password=clezito001");
statement = connect.createStatement();
// Resultset get the result of the SQLquery
resultSet = statement.executeQuery("SELECT * FROM alunos " +
"WHERE Nome like '"+student+"%' Order By Nome;");
while (resultSet.next())
{
id = resultSet.getInt("id");
nome = resultSet.getString("nome");
cpf = resultSet.getString("cpf");
tel = resultSet.getString("telefone");
end = resultSet.getString("endereco");
bai = resultSet.getString("bairro");
cid = resultSet.getString("cidade");
uf = resultSet.getString("uf");
cep = resultSet.getString("cep");
if (nome.startsWith(student.toUpperCase()))
{
System.out.println("\n===================================================");
System.out.println("ID: " + id);
System.out.println("Name: " + nome);
System.out.println("CPF: " + cpf);
System.out.println("Phone: " + tel);
System.out.println("Address: " + end);
System.out.println("Neighborhood: " + bai);
System.out.println("City: " + cid);
System.out.println("UF: " + uf);
System.out.println("CEP: " + cep);
System.out.println("===================================================");
}else{ //Se nao encontrar, informa que nao existe o aluno
System.out.println("\n***************************************************");
System.out.println("| Student not found! |");
System.out.println("***************************************************\n");
}
}
} catch (Exception e) {
throw e;
} finally {
close();
}
}
Valeu galera!!!