0
List < VarUnica > list = new ArrayList < VarUnica > ();
String queri = "select cpf from funcionario";
VarUnica alt = new VarUnica();
Statement ttpa;
try {
ttpa = Conexao.getConexao().createStatement();
ResultSet tr = ttpa.executeQuery(queri);
while (tr.next()) {
alt.setRp(tr.getString("cpf"));
list.add(alt);
}
for (VarUnica c: list) {
System.out.println(alt.getRp());
}
} catch (SQLException ex) {
Logger.getLogger(InserindoDados.class.getName()).log(Level.SEVERE, null, ex);
}
}
Someone can get me where I’m going wrong,.
– Gleiston Jose de Santana
Can someone tell me where I’m going wrong,.
– Gleiston Jose de Santana
Try putting this:
VarUnica alt = new VarUnica();inside the While– DiegoAugusto
you don’t need the other setters on
alt? if you havealt.setRp()must have another likealt.setNome(),alt.setAlgumaOutraCoisa()?– rray
Can post the code where you open the connection to the bank?
– Matheus
First of all try to eliminate the possibility of errors, before the while see how many elements have the result set. I also think it should be because you are not instantiating the object within while, so it is not creating a new instance.
– Guilherme Guini
In column Cpf I have 3 records.
– Gleiston Jose de Santana
@Gleistonjosedesantana Tested what I said?
– DiegoAugusto
tested plus gave error...
– Gleiston Jose de Santana
@Gleistonjosedesantana What mistake?
– DiegoAugusto
Look in the database has 3 records,the result in the console is 3 records,more these 3 records is the same,ie are coming 3 equal data,what I want is to come the 3 different,got it.
– Gleiston Jose de Santana
@Gleistonjosedesantana I understood, but you did not formulate your question well and I think you are not doing right what I said.
– DiegoAugusto
apologies, could guide me in a clearer way.
– Gleiston Jose de Santana
People the idea of standardizing worked, more I had to put in Sys...(c.getRp);..... Thanks for the strength of the crowd.
– Gleiston Jose de Santana
You were only changing the object reference to each iteration. So you could only catch one object, the last one. A new object must be instantiated at each iteration.
– Paulo Weverton