1
People are the following, I’m wanting to upload all this data in my graphical interface, the idea is that the user type the Cpf(Primary key) of it and after that is loaded all this data for it to update, I want to know how to make this Cpf after the user, type load the data, I tried to do and more is not working.
DadosFuncionario funcionario = new DadosFuncionario();
try{
Conexao.Conectar();
String sql = "select * from funcionario";
PreparedStatement query;
query = con.prepareStatement(sql);
query.setString(1, campoDigCpf.getText());
// query.executeQuery();
ResultSet rs = query.executeQuery(sql);
//tapete.setNome(rs.getString("nome");
while (rs.next()) {
String cargoOcupado = rs.getString("cargoOcupado");
String nome = rs.getString("nome");
String cpf = rs.getString("cpf");
int rg = rs.getInt("rg");
String orgaoExped = rs.getString("orgaoExped");
Date dataExped = rs.getDate("dataExped");
Date dataDeNascimento = rs.getDate("dataDeNascimento");
String email = rs.getString("email");
String estadoCivil = rs.getString("estadoCivil");
String sexo = rs.getString("sexo");
int cnh = rs.getInt("cnh");
int titulo = rs.getInt("titulo");
int zona = rs.getInt("zona");
int secao = rs.getInt("secao");
int carteiraTrabalho = rs.getInt("carteiraTrabalho");
int serieCtrabalho = rs.getInt("serieCtrabalho");
int cartResevista = rs.getInt("cartResevista");
int serieResevista = rs.getInt("serieResevista");
String racaCor = rs.getString("racaCor");
int pis = rs.getInt("pis");
}
query.close();
String sql2 = "select * from endereco";
PreparedStatement stmt;
stmt = con.prepareStatement(sql2);
ResultSet rs1 = stmt.executeQuery(sql2);
while (rs1.next()) {
int numero = rs1.getInt("numero");
int numeroEmpresa = rs1.getInt("numeroEmpresa");
String rua = rs1.getString("rua");
String ruaEmpresa = rs1.getString("ruaEmpresa");
String bairro = rs1.getString("bairro");
String bairroEmpresa = rs1.getString("bairroEmpresa");
String cidade = rs1.getString("cidade");
String cidadeEmpresa = rs1.getString("cidadeEmpresa");
int cep = rs1.getInt("cep");
int cepEmpresa = rs1.getInt("cepEmpresa");
String ufFuncionario = rs1.getString("ufFuncionario");
String ufEmpresa = rs1.getString("ufEmpresa");
}
stmt.close();
String sql3 = "select * from dadosprofissionais";
PreparedStatement stmt1;
stmt1 = con.prepareStatement(sql3);
ResultSet rs2 = stmt1.executeQuery(sql3);
while (rs2.next()) {
String diretoria = rs2.getString("diretoria");
String departamento = rs2.getString("departamento");
String divisao = rs2.getString("divisao");
int matricula = rs2.getInt("matricula");
String inss = rs2.getString("inss");
int contaCorrente = rs2.getInt("contaCorrente");
int agenciaBanco = rs2.getInt("agenciaBanco");
int numeroBanco = rs2.getInt("numeroBanco");
String nivelEscolar = rs2.getString("nivelEscolar");
String periodo = rs2.getString("periodo");
Date dataAdmissao = rs2.getDate("dataAdmissao");
String conselho = rs2.getString("conselho");
}
stmt1.close();
String sql4 = "select * from informacoesgerais";
PreparedStatement stmt2;
stmt2 = con.prepareStatement(sql4);
ResultSet rs3 = stmt2.executeQuery(sql4);
while (rs3.next()) {
String concordo = rs3.getString("concordo");
String observacoes = rs3.getString("observacoes");
Date dataFormulario = rs3.getDate("dataFormulario");
}
stmt2.close();
String sql5 = "select * from telefone";
PreparedStatement stmt3;
stmt3 = con.prepareStatement(sql5);
ResultSet rs4 = stmt3.executeQuery(sql5);
while (rs4.next()) {
int foneFuncionario = rs4.getInt("foneFuncionario");
int celFuncionario = rs4.getInt("celFuncionario");
int ramal = rs4.getInt("ramal");
int foneEmpresa = rs4.getInt("foneEmpresa");
}
stmt3.close();
String sql6 = "select * from dependentes";
PreparedStatement stmt4;
stmt4 = con.prepareStatement(sql6);
ResultSet rs5 = stmt4.executeQuery(sql6);
while (rs5.next()) {
String conjugue = rs5.getString("conjugue");
String pai = rs5.getString("pai");
String mae = rs5.getString("mae");
int qtdDeFilhos = rs5.getInt("qtdDeFilhos");
int totalDependentes = rs5.getInt("totalDependentes");
String profissaoConjugue = rs5.getString("profissaoConjugue");
String profissaoPai = rs5.getString("profissaoPai");
String profissaoMae = rs5.getString("profissaoMae");
String parenteEmpresa = rs5.getString("parenteEmpresa");
String nomeParenEmpresa = rs5.getString("nomeParenEmpresa");
String grauParentesco = rs5.getString("grauParentesco");
}
stmt4.close();
Conexao.con.close();
} catch(SQLException e){
JOptionPane.showMessageDialog(null, "Ocorreu no erro sql... " + e.getMessage());
}
JOptionPane.showMessageDialog(null, "Dados carregados com sucesso");
Type where? Ta using swing? The edit had made the question clearer, edit it again, have confusing snippets because of the score.
– user28595
I am using swing,the select are right the only thing missing and the part that the user type Cpf(that an id(Primary key)), I use a select button that loads all this data,.
– Gleiston Jose de Santana
You are using prepareStatement but your querys have no arguments and no filters. Review your querys, prepareStatement arguments are useless if they are not informed in the query where they should be replaced.
– user28595
Is there a relationship between the tables (there are foreign key fields between them)? I think we can optimize this much query, but you need to show how are the tables and the relationship between them.
– user28595