Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to JasperReports SQLl statement from Java

I'm using JasperReports engine, and one of the reports gets data from database executing SQL statement. Is there a way to pass parameters to that query?

Thanks in advance!

like image 761
Andrew Avatar asked Sep 17 '10 08:09

Andrew


1 Answers

First, create a new parameter in your report. Then insert the parameter in your query, for example:

SELECT name, department FROM employees WHERE employee_id = $P{employeeId}

Make sure your parameter types matches the data type of the columns in your database. Finally, simply pass your parameters to the JasperReports engine. An example would be:

parameters.put("employeeId", Long.valueOf(14309));
JasperRunManager.runReportToPdf(reportFile, parameters, connection);
like image 133
Giorgos Dimtsas Avatar answered Sep 20 '22 13:09

Giorgos Dimtsas