I'm having a problem printing the MySQL data in Eclipse. When I put to print the list of the registered data it is printing 3 times each information.
I know where the problem is, but I can not see the solution. My database has a schema and two tables ( cliente
and endereco
). What happens is that when I enter the information of 3 people, for example, Eclipse prints 3 times each information because the rs.next()
is taking from the two tables.
See:
public void listarClientes() {
String sql = "SELECT * FROM locadora.cliente, locadora.endereco";
try {
PreparedStatement ps = jdbc.getConexao().prepareStatement(sql); ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.println("Nome: " + rs.getString("nome") + " - Código: " + rs.getString("codigo") + " - Bom pagador: " + rs.getBoolean("seBomPagador") + " - Telefone: " + rs.getString("telefone"));
System.out.println("Tipo de endereço: " + rs.getString("tipo_endereco") + " - Logradouro: " + rs.getString("logradouro") + " - Bairro: " + rs.getString("bairro") + " - Cidade: " + rs.getString("cidade") + " - UF: " + rs.getString("uf") + " - Cep: " + rs.getString("cep"));
System.out.println();
}
System.out.println(); rs.close();
} catch (Exception e) { // TODO: handle exception
System.out.println("Erro na listagem dos clientes!");
}