I'm doing a database program and I'm not able to make my list appear in jtable
. I created the method and at the time I call it my method of error, can someone help me the code is down there?
Error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at presentation.Customer.formInternalFrameOpened (ClientClient.java: 593)
List method
public List<cliente>preencherTabela(){
String sql = "select * from cliente";
cliente c=new cliente();
List<cliente> lista = new ArrayList<>();
try(PreparedStatement stmt = conexao.prepareStatement(sql)){
ResultSet rs = stmt.executeQuery();
while(rs.next()){
c.setIdcodigo(rs.getInt("idcodigo"));
c.setNome(rs.getString("nome"));
c.setEndereco(rs.getString("endereco"));
c.setEmail(rs.getString("email"));
c.setCidade(rs.getString("cidade"));
c.setBairro(rs.getString("bairro"));
c.setTelefone(rs.getString("telefone"));
c.setCelualr(rs.getString("celular"));
c.setCep(rs.getString("cep"));
c.setRg(rs.getString("rg"));
c.setCpf(rs.getString("cpf"));
c.setDatanascimento(rs.getString("datanascimento"));
c.setUf(rs.getString("uf"));
c.setSexo(rs.getString("sexo"));
}
}catch (SQLException ex) {
JOptionPane.showMessageDialog(null,"Usuario nao encontrado" + ex);
}
return lista;
}
}
code to call the method
private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
cliente c = new cliente();
List<cliente> lista = new ArrayList<>();
Conexao con=null;
lista=con.preencherTabela();
for(int i=0;i<lista.size();i++){
c=lista.get(i);
jPcad.setValueAt(c.getIdcodigo(), i, 0);
jPcad.setValueAt(c.getNome(), i, 1);
}
}