Problem with parameter passing to queryString

0

Hello 

I'm using JesperReports Library and I'm trying to filter sql query. Unfortunately parameter is ignored and default value from <defaultValueExpression> is always used. Even if I would delete <defaultValueExpression> with its value It will never return correct result (Empty result every time). Part of my code is pasted below.

 

.jrxml code

<subDataset name="tableDataset" uuid="ad14c38d-49b3-49db-a2f7-1d24458f7e5f">
   <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
   <parameter name="queryParam" class="java.lang.Integer">
      <defaultValueExpression><![CDATA[210]]></defaultValueExpression>
   </parameter>
   <queryString language="SQL">
      <![CDATA[SELECT * FROM skd where skd_km = $P{queryParam}]]>
   </queryString>
   <field name="skd_id" class="java.lang.Integer"/>
   <field name="skd_nd"/>
   <field name="skd_km" class="java.lang.Integer"/>
   <field name="skd_m" class="java.lang.Integer"/>
   <field name="skd_odc" />
   <field name="skd_kod" class="java.lang.Long"/>
   <field name="skd_nr" class="java.lang.Integer"/>
   <field name="skd_pkt" class="java.lang.Integer"/>
</subDataset>

.java code

        try (Connection conn = DriverManager.getConnection(dbURL, username, password)) {
 
            JasperReport jasperReport = JasperCompileManager.compileReport(
                    "src/main/resources/tempSKDFiltered.jrxml");
 
            Map<String, Object> parametersMap = new HashMap();
            parametersMap.put("queryParam", 229);
 
            JasperPrint jasperPrint = JasperFillManager.fillReport(
                    jasperReport, parametersMap, conn);
 
            JasperExportManager.exportReportToPdfFile(
                    jasperPrint, "SKDFilter.pdf");
 
        } catch (JRException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

Does anybody have an idea what I'm doing wrong?

Thanks.

bmeg's picture
3
Joined: Aug 31 2017 - 1:28am
Last seen: 1 year 5 days ago

2 Answers:

0

Try setting the default value as 0.

hozawa's picture
51038
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 months 1 week ago
0

src? Really?
How RunReport.class not RunReport.java (your ".java code") can compile jrxml at "src/main/resources/tempSKDFiltered.jrxml" ?

sanbez's picture
834
Joined: Jan 11 2011 - 2:06am
Last seen: 4 weeks 1 day ago
Feedback
randomness