Jump to content
Changes to the Jaspersoft community edition download ×

Report Fields Not Rendering SQL Query Results


rauper

Recommended Posts

Hi All,

Could someone please help me - I'm really stuck in this report.

I'm using Ireport w/netbeans, trying to create a dynamic report based on SQL query.

I'm passing the parameter from a java object using the params HashMap

params.put("id_supplier", this.getCurrentSupplier().getSupplierId()); // Queries database for supplier id

Then i pass the parameter hashmap to my report:

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

JasperPrintManager.printReport(jasperPrint, true);

Within my SupplierReport.jrxml file, I have placed the parameter as tutorials state

    <parameter name="id_supplier" class="java.lang.Integer"/>

and added the database query to return the information


    <queryString>
        <![CDATA[sELECT product_description,approved,report FROM product WHERE id_supplier=$P{id_supplier}]]>
    </queryString>

added the field onto the report

<textField isBlankWhenNull="true">
   <reportElement x="13" y="11" width="342" height="20"/>
      <textElement verticalAlignment="Middle">
         <font fontName="Verdana" size="12"/>
      </textElement>
      <textFieldExpression class="java.lang.String"><![CDATA[$F{product_description}]]>          </textFieldExpression>
</textField>

Yet when I print my report it prints nothing.

Someone please help me.

Many thanks

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I originally thought it might be a data type problem, where you defined a parameter as type integer but were then potentially filling it with a char or something else.  But looking at it again, I think the problem is your JREmptyDatasource in your fillReport call.  Doesn't that have to be the connection to your actual database you're trying to query, or else you're NOT going to get back any result set, right?  Here are some lines of code we just started working on to take an existing .jrxml file and compile/run it.  The following lines show how you can read in what parameters the report expects and how you can fill in a parameter (although the way this sample code reads in parameters is for a generic solution where you can prompt, etc., whereas the lines where I fill in a parameter (pasted from your example) is hardcoded, and obviously those two approaches probably wouldn't coexist in the same code.)  Good luck!

      Connection connection = connectToDatabase(databaseName, userName, password); // a method we have defined
      JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
      JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
      JRParameter[] jrParameters = jasperReport.getParameters();
      for (JRParameter param : jrParameters) {

      // in here you have access to param.getName(), param.getValueClassName(), param.isSystemDefined(), etc.
      }
      HashMap params = new HashMap();

 

   params.put("id_supplier", this.getCurrentSupplier().getSupplierId()); // Queries database for supplier id


      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);
      JRPdfExporter export = new JRPdfExporter();
      export.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
      export.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,"output.pdf");
      export.exportReport();
 

Carl

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...