0
I have a Registration Class, which is responsible for the View. I have this code:
public void listarTabela(){
DefaultTableModel val = (DefaultTableModel) jTable3.getModel();
val.getDataVector().removeAllElements();
UsuarioDAO usDAO = new UsuarioDAO();
List<Usuario> usuarios = usDAO.listarUsuarios();
int i = 0;
while(usuarios.size() > i){
val.addRow(new Object[] {String.valueOf(usuarios.get(i).getId()), usuarios.get(i).getNome(),
usuarios.get(i).getCpf(), usuarios.get(i).getEmail(), usuarios.get(i).getTelefone()});
i++;
In the User class (class responsible for the sql treatments that each view button has running), I have the code:
public List<Usuario> listarUsuarios(){
String sql = "SELECT * FROM usuario";
ResultSet rs;
List<Usuario> usuarios = new ArrayList<Usuario>();
try{
PreparedStatement stmt = conecta.prepareStatement(sql);
rs = stmt.executeQuery();
while(rs.next()){
Usuario us = new Usuario();
us.setId(rs.getInt("id"));
us.setNome("nome");
us.setEmail("email");
us.setCpf("cpf");
us.setTelefone("telefone");
usuarios.add(us);
}
rs.close();
stmt.close();
return usuarios;
}catch(SQLException e){
throw new RuntimeException(e);
}
}
I also have a Jtable and a Jbutton that calls listarTabela();
. Every time I click the button, even if I call the class builder, any time I call the "listarTabela()
" She returns to me at Jtable:
1,name,Cpf,email,phone
2,name,Cpf,email,phone
3,name,Cpf,email,phone
The database is ok, it returns the correct values.
Please access the link and provide a [mcve] so that it is possible to test the problem.
– user28595
What is missing ?
– Pedro Anselmo