Bom, eu estou fazendo uma aplicação que gera relatórios, e em um determinado método preciso listar valores de uma tabela, mas não sei como fazer.
Seque o codigo abaixo:
public PecaEntity selecionar(final String id) throws Exception {
PecaEntity entity = null;
PreparedStatement stmt;
ResultSet rs;
try {
openDb();
stmt = con.prepareStatement(SQL_ORDEM);
stmt.setString(1, id);
rs = stmt.executeQuery();
if (rs.next()) {
entity = new PecaEntity();
entity.setCodEuro(rs.getString("codeuro"));
entity.setCodPe(rs.getString("codpe"));
entity.setData(rs.getString("data"));
entity.setHora(rs.getString("hora"));
entity.setDescricao(rs.getString("descricao"));
entity.setDesenho(rs.getString("desenho"));
entity.setMp(rs.getString("mp"));
entity.setTipo(rs.getString("tipo"));
entity.setNorma(rs.getString("norma"));
entity.setTraTermico(rs.getString("tratermico"));
entity.setAcabamento(rs.getString("acabamento"));
entity.setPesoMt(rs.getString("pesomt"));
entity.setPesoB(rs.getString("pesob"));
entity.setDiametro(rs.getString("diametro"));
entity.setCompTotal(rs.getString("comptotal"));
entity.setPesoTotal(rs.getString("pesototal"));
entity.setCliente(rs.getString("cliente"));
entity.setOpnr(rs.getString("opnr"));
entity.setPedido_nr(rs.getString("pedido_nr"));
entity.setData_pedido(rs.getString("data_pedido"));
entity.setQuantidade_peca(rs.getString("quantidade_peca"));
entity.setPrazo_estimado(rs.getString("prazo_estimado"));
}
for (int i = 1; i <= 15; i++) {
String nomeCampo = "combo" + i;
PecaItemEntity pecaItem = new PecaItemEntity(rs.getString(nomeCampo));
entity.addPecaItemEntity(pecaItem);
}
selecionarSequencia(id);
} catch (Exception ex) {
System.out.println("Erro ao selecionar peca.\n" + ex);
} finally {
con.close();
}
return entity;
}
public PecaEntity selecionarSequencia(final String id) throws Exception {
PecaEntity entity = null;
PreparedStatement stmt;
ResultSet rs;
try {
openDb();
stmt = con.prepareStatement(SQL_SEQUENCIA);
stmt.setString(1, id);
rs = stmt.executeQuery();
if (rs.next()) {
entity = new PecaEntity();
PecaItemEntity pecaItem = new PecaItemEntity(rs.getString("tempo_setup_real"));
entity.addPecaItemEntity(pecaItem);
}
} catch (Exception ex) {
System.err.println("Erro ao selecionar Sequencia: " + ex);
} finally {
con.close();
}
return entity;
}
E é o segundo método que precisa listar, mas não estou conseguindo. Não sei se a construtora está errado ou algo no próprio método.
Eu chamo o segundo método no primeiro, mas tb nao sei se esta correto.
Sou iniciante em Java, sejam bem claros por favor
Abraços