1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JRDesignQuery;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import java.util.HashMap;
import java.util.Map;
public JasperPrint loadReport() throws SQLException{
Connection myConn = null;
JasperPrint result = new JasperPrint();
try{
result = new JasperPrint();
String osdSql="SELECT ... " +
"FROM ... " +
"GROUP BY ... " +
"HAVING ...";
String jasperFile= "C:\\netdados\\EclipseProjectsWeb\\og\\WebContent\\reports\\rptOsdDem.jrxml";
JasperDesign jasperDesign = JRXmlLoader.load(jasperFile);
JRDesignQuery query = new JRDesignQuery();
query.setText(osdSql);
jasperDesign.setQuery(query);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("statM1", strMoisF.format(dateTimeDiffere("month", -1).getTime()));
parameters.put("statM2", strMoisF.format(dateTimeDiffere("month", -2).getTime()));
parameters.put("statM3", strMoisF.format(dateTimeDiffere("month", -3).getTime()));
myConn = dataSource.getConnection();
result = JasperFillManager.fillReport(jasperReport, parameters, myConn);
}catch(Exception e){
JOptionPane.showMessageDialog(null, e.getMessage());
}finally{
if (myConn!=null) myConn.close();
}
return result;
} |
Partager