Bom dia Pessoal.
Estou fazendo um select de alguns campos de minha tabela e tentando joga-los em minha jTable.
Sempre fiz desta forma, porem sempre pesquisei TODOS os campos de minha tabela. Desta vez como sao muitos campos existentes na tabela, quero carregar apenas os mais importantes na jTable, porem estou com problema, nao sei o que pode estar errado nesta minha forma de utilizar.
Abaixo segue o codigo.
Muito obrigado…
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String Consulta= "select rg, cpf, nome, cargo from tab_fun where nome like" + " '"+jTextField1.getText()+"%';";
DefaultTableModel table_fun= (DefaultTableModel) jTable1.getModel();
int l= jTable1.getRowCount();
for (int row= l; row>0; row--){
table_fun.removeRow(row);
}
try{
Class.forName("org.postresql.Driver");
con= DriverManager.getConnection("jdbc:postgresql://localhost:5432/cpr", "postgres", "123456");
Statement stm= con.createStatement();
ResultSet rs= stm.executeQuery(Consulta);
while (rs.next()){
//int iCodFun= rs.getInt("id_fun");
String cRG= rs.getString("rg");
String cCPF= rs.getString("cpf");
String cNome= rs.getString("nome");
//String cCivil= rs.getString("ecivil");
//String cEndereco= rs.getString("ende");
//String cBairro= rs.getString("bairro");
//String cCidade= rs.getString("cidade");
//String cUF= rs.getString("uf");
//int iNasci= rs.getInt("nasci");
//int iRegistro= rs.getInt("registro");
String cCargo= rs.getString("cargo");
//int iDtAdmissao= rs.getInt("dtadmi");
//String cNCarteira= rs.getString("ncarteira");
//String cSerie= rs.getString("serie");
//int iDtRegistro= rs.getInt("dtregistro");
//String cSalario= rs.getString("salario");
//int iDtDemissao= rs.getInt("demissao");
//String iMotivoSaida= rs.getString("saida");
table_fun.addRow(new Object [] {cRG, cCPF, cNome, cCargo});
}
con.close();
stm.close();
rs.close();
}
catch(SQLException e){
JOptionPane.showMessageDialog(this, "Erro Cmdo SQL"+ e.getMessage());
}
catch(ClassNotFoundException e){
JOptionPane.showMessageDialog(this,"Driver não encontrado");
}
}