Estou com duvida quando utilizo a herança no meu metodo consultar
Me ajudem…
public List consultar(String parametro) {
List<Ocorrencia> list_ocorrencia = new ArrayList<Ocorrencia>();
try {
Connection conn = Conexao.getConnection();
String sql =
"select descricao,data_ocorrencia,servico from ocorrencia where idocorrencia=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1, Integer.parseInt(parametro));
ResultSet rs = pst.executeQuery();
while(rs.next()){
Ocorrencia ocorrencia = new Ocorrencia();
//quando uso esse atributos da propria classe ocorrencia, ele vai legal
ocorrencia.setDescricao(rs.getString("descricao"));
ocorrencia.setData(rs.getString("data_ocorrencia"));
// aqui ele acusa que esta nulo
ocorrencia.getServicos().setDescricaoServ(rs.getString("servico"));
list_ocorrencia.add(ocorrencia);
}
pst.close();
rs.close();
return list_ocorrencia;
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.getMessage());
}
return list_ocorrencia;
}
public void Excluir(DomainObject domainObject) {
try {
Connection conn = Conexao.getConnection();
String sql = "Delete from ocorrencia where idocorrencia=?";
Ocorrencia ocorrencia = (Ocorrencia) domainObject;
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1, ocorrencia.getIDOcorrencia());
//Executando a sql
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "excluido");
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
Meu JFrame
IFachadaOcorrencia fachadaoco = new Fachadaocorrencia();
List<Ocorrencia> list_ocorrencia = fachadaoco.consultar(tfconsulta.getText());
for(Ocorrencia oco :list_ocorrencia) {
tfdescricaoocorrencia.setText(oco.getDescricao());
tfdata.setText(oco.getData());
tfservico.setText(oco.getServicos().getDescricaoServ());