My report jrxml file looks like
<band height="256" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="555" height="50" uuid="eb5b00f3-c370-4c7f-bb10-b7589ff293ff"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="listDataset" uuid="364ec058-5b7e-43e0-9272-92907dfba7f3">
<datasetParameter name="REPORT_DATE">
<datasetParameterExpression><![CDATA[$P{REPORT_DATE}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[$P{REPORT_CONNECTION}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="50" width="555">
<staticText>
<reportElement x="1" y="2" width="100" height="20" uuid="cd4ed06d-2c04-4342-8cc2-ff7077621eb6"/>
<text><![CDATA[LABEL_VALUE]]></text>
</staticText>
<textField>
<reportElement x="101" y="2" width="129" height="20" uuid="d307fa41-0962-4b17-812d-774262e55e9e"/>
<textFieldExpression><![CDATA[$F{LABEL_VALUE}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="230" y="2" width="140" height="20" uuid="20989891-eb66-45ee-8fbb-b7c53a65f0fe"/>
<text><![CDATA[ATTRIBUTE_VALUE]]></text>
</staticText>
<textField>
<reportElement x="370" y="2" width="184" height="20" uuid="fa972e53-dc8a-402e-96ad-9428b402ccd8"/>
<textFieldExpression><![CDATA[$F{ATTRIBUTE_VALUE}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
But here I am getting a ClassCastException,
java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to net.sf.jasperreports.engine.JRDataSource
I am not able to figure it out, why?
From JasperReports api JRDatasetRun
A dataset run declaration supplies the values for the dataset parameters as well as the data source through which the dataset will iterate. Optionally, a java.sql.Connection can be passed to the dataset instead of a JRDataSource instance, when there is a SQL query associated with the dataset. This query is executed by the engine using the JDBC connection and the java.sql.ResultSet object obtained is iterated through.
Conclusion when you run a dataset datasetRun
you can either:
Pass a JRDatasource
using the dataSourceExpression
tag
Pass a JDBC connection using the connectionExpression
tag
Not pass anything.
So what are you doing wrong?
You are passing a JDBC connection in the dataSourceExpression
tag not in the connectionExpression
tag, JasperReports expect it to be a JRDatasource and tries to cast it as such.
If you like to pass the report connection your should use connectionExpression
as below.
<datasetRun subDataset="listDataset" uuid="364ec058-5b7e-43e0-9272-92907dfba7f3">
<datasetParameter name="REPORT_DATE">
<datasetParameterExpression><![CDATA[$P{REPORT_DATE}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>