Olá amigos
estou tentando visualizar um relatório feito no ireport 3.7.2.
No ireport ele funciona normalmente passando os parametros de data, mas no programa fica em loop e não faz nada:
DATAINI
Parameters Class java.util.Date
Default value Expression $P{DATAINI}.getTime()
DATAFIM
Parameters Class java.util.Date
Default value Expression $P{DATAFIM}.getTime()
select processo,dataaudiencia,horaaudiencia,reclamante,reclamado,assunto,situacao
from audiencia
where dataaudiencia>=$P{DATAINI} and
dataaudiencia<=$P{DATAFIM}
order by dataaudiencia
No programa:
public void imprimirAudienciaButton_action(ActionEvent e) throws ParseException, JRException {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
controlDataInicial.setDefaultDate(Calendar.getInstance(Locale.ENGLISH));
controlDataFinal.setDefaultDate(Calendar.getInstance(Locale.ENGLISH));
dtInicial = formatter.format(controlDataInicial.getDate());
dtFinal = formatter.format(controlDataFinal.getDate());
dataInicial = new java.sql.Date(formatter.parse(dtInicial).getTime());
System.out.println( formatter.format(dataInicial) );
dataFinal = new java.sql.Date(formatter.parse(dtFinal).getTime());
System.out.println( formatter.format(dataFinal) );
RelatorioMBean relAudiencia = new RelatorioMBean(conn);
HashMap map = new HashMap ();
relAudiencia.geraRelatorio("/relatorios/relaudiencia.jasper",dataInicial,dataFinal, map);
}
no bean:
public class RelatorioMBean {
//extends AbstractCrudBean<Relatorio> {
public Connection conn = null;
public RelatorioMBean(Connection conn) throws JRException {
this.conn = conn;
}
// public static void main(String[] args) throws JRException, Exception {
// new geraRelatorio();
// }
public void geraRelatorio(String pathReport, Date dataInicial, Date dataFinal) throws JRException {
HashMap map = new HashMap();
geraRelatorio(pathReport, dataInicial, dataFinal, map);
}
public void geraRelatorio(String pathReport, Date dataInicial, Date dataFinal, HashMap map) throws JRException {
map.put("DATAINI",dataInicial);
map.put("DATAFIM",dataFinal);
geraRelatorio(pathReport, map);
}
public void geraRelatorio(String pathReport, HashMap map) throws JRException {
//supondo que o teu ficheiro teste.jasper esteja dentro da tiua aplicação
Map<String, Object> parametros = new HashMap<String, Object>();
URL reportURL = RelatorioMBean.class.getResource(pathReport);
String reportDir = reportURL.getFile();
// parametros.put("REPORT_PATH", reportDir);
URL relatorioURL = RelatorioMBean.class.getResource(pathReport);
// File file = new File(relatorioURL.getFile());
// JasperReport relatorioJasper = (JasperReport) JRLoader.loadObject(relatorioURL);
JasperReport jr = (JasperReport) JRLoader.loadObject(relatorioURL);
JasperPrint jp = JasperFillManager.fillReport(jr, map, conn);
JasperViewer jv = new JasperViewer(jp, false);
jv.setVisible(true);
}
Saída no debug:
Datainicial 2008-05-10
Data Fina 2010-05-10
relatorioURL - file:/home/silvio/NetBeansProjects/Consumidor/build/classes/relatorios/relaudiencia.jasper
reportURL - file:/home/silvio/NetBeansProjects/Consumidor/build/classes/relatorios/relaudiencia.jasper
reportDir - /home/silvio/NetBeansProjects/Consumidor/build/classes/relatorios/relaudiencia.jasper
alguém pode ajudar?
Muito Obrigrado