I am trying to create JR report which is taking start_date and end_date as parameters.
The query:
SE
Your code is wrong.
You should pass parameters as below:
Map<String, Object> map = new HashMap<String, Object>();
map.put("frm_date", frm_dte);
map.put("to_date", to_dte);
You don't need to add P${}
to the parameter's name.
There are a lot of samples in JasperReports distribution package.
You can look at this sample for more details.
private JasperPrint generateReport() {
Connection conn = null;
JasperPrint myJPrint = null;
try {
conn =yourconnectionName;
// parameters to be passed to the report
Map<String, Object> params = new HashMap();
// Loading my jasper file
JasperDesign jasperDesign = null;
JasperReport jasperReport = null;
params.put("REPORT_DIR",yourClassName.class.getClassLoader()
.getResource("yourJasperFileName.jrxml").toString().replace("yourJasperFileName.jrxml", ""));
jasperDesign = JasperManager.loadXmlDesign(yourClassName.class
.getClassLoader().getResourceAsStream("yourJasperFileName.jrxml"));
params.put("joining_date", frm_dte);
params.put("leaving_date", frm_dte);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
/*
* Filling the report with data from the database based on the
* parameters passed.
*/
myJPrint = JasperFillManager.fillReport(jasperReport, params, conn);
params.clear();
} catch (JRException ex) {
ex.printStackTrace();
}
return myJPrint;
}
You can pass date as string format type as follow,
if(from_date!=null)
{
formattedEndDate=new SimpleDateFormat("yyyy-MM-dd").format(from_date);
}
if(getStartDate()!=null)
{
formattedStartDate=new SimpleDateFormat("yyyy-MM-dd").format(to_date);
}