JasperReport showing null values when the query is not empty

I am using JasperReports to create reports in Java. I use the following code to try to generate the report:

connect.query = "SELECT employee_id, employee_first_name, employee_last_name, salary, date_of_enrollment FROM employees";

try {

    connect.prstmt = connect.con.prepareStatement(connect.query);

    connect.rs = connect.prstmt.executeQuery();

    JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource(connect.rs);

    try {

         InputStream input = new FileInputStream(new File("jrxml/employees2.jrxml"));

        JasperDesign jasperDesign = JRXmlLoader.load(input);

        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,null,new JREmptyDataSource());

        OutputStream output = new FileOutputStream(new File("reports/employees.pdf"));

        JasperExportManager.exportReportToPdfStream(jasperPrint, output);

    }

    catch (JRException e) {

          e.printStackTrace();

    }

    catch (FileNotFoundException y) {

        y.printStackTrace();

    }

 }

 catch (SQLException e) {

        e.printStackTrace();

 }

 

the problem is that the fields appear empty in the jasper report even though the query does return values. I populated a table with the same query and it worked fine. I should also note that if I create the report by embedding the query into the jrxml file then everything works fine, but it is important that I not do that because the parameters of the query aill change from time to time. Can anyone help me with this? Thanks

najib.mozahem's picture
Joined: Apr 4 2014 - 10:35pm
Last seen: 9 years 5 months ago

0 Answers:

No answers yet
Feedback
randomness