I'm trying to make my first steps with JasperReports and iReport. Recently I solved a problem with Database Connection in this post. After that I created another successful connection to a MySQL DB just to reinforce the knowledge; I made a query but now I'm getting another error related -I suppose- to the query itself or something like that.
The situation
When I try to create a Report query the fields (table columns) are retrieved and it's type is recognized correctly but the data (rows) gives me an error with the message
Error: net.sf.jasperreports.engine.JRException: Error excecuting SQL statement for: data
The error is shown in the screenshot below:
Then, when I try to preview the report with the fields of the query I get the following error:
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Field not found : idaddress
2. Field not found : city
at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:271)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:153)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:354)
at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:270)
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:563)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:528)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
In the jrxml
file the fields are defined properly as I saw in this other post as follow:
<subDataset name="MyDataset" uuid="b9d7b569-d19e-451e-8a15-c558918e1698">
<queryString language="SQL">
<![CDATA[SELECT
address.`idaddress` AS address_idaddress,
address.`city` AS address_city
FROM
`address` address]]>
</queryString>
<field name="address_idaddress" class="java.lang.Integer"/>
<field name="address_city" class="java.lang.String"/>
</subDataset>
The project
The complete jrxml
file is this:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="PrimerReporte" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="eb8d4459-c8dc-4c96-bc35-ac988007e32a">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#A52A2A">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#FFBFBF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#FFEFEF"/>
</conditionalStyle>
</style>
<subDataset name="MyDataset" uuid="b9d7b569-d19e-451e-8a15-c558918e1698">
<queryString language="SQL">
<![CDATA[SELECT
address.`idaddress` AS address_idaddress,
address.`city` AS address_city
FROM
`address` address]]>
</queryString>
<field name="address_idaddress" class="java.lang.Integer"/>
<field name="address_city" class="java.lang.String"/>
</subDataset>
<parameter name="idaddress" class="java.lang.Integer">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="city" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
address.`idaddress` AS address_idaddress,
address.`city` AS address_city
FROM
`address` address]]>
</queryString>
<field name="address_idaddress" class="java.lang.Integer"/>
<field name="address_city" class="java.lang.String"/>
<filterExpression><![CDATA[$F{idaddress}]]></filterExpression>
<group name="city">
<groupExpression><![CDATA[$F{city}]]></groupExpression>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="121" y="0" width="313" height="49" uuid="e3c5e2b7-14a4-4e26-a90c-ae4702f4ac65"/>
<textElement>
<font size="36"/>
</textElement>
<textFieldExpression><![CDATA[Mi primer reporte]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch">
<staticText>
<reportElement x="22" y="0" width="510" height="35" uuid="7d375361-1b1d-4a7b-8788-9dd432b86c43"/>
<textElement>
<font size="18"/>
</textElement>
<text><![CDATA[Este es un reporte de prueba para aprender a usar iReport]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement key="table" style="table" x="0" y="0" width="401" height="80" uuid="8c775bc1-4076-44c4-a7af-1fc405283908"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="MyDataset" uuid="12ca7d6a-d625-42ab-bff9-57937d50f096">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
</datasetRun>
<jr:column width="200" uuid="37b69ab0-be68-4dda-8739-08860a5dd8c7">
<jr:tableHeader style="table_TH" height="30" rowSpan="1"/>
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="91dcc02e-4f54-446e-9092-d8e8fef6bc78"/>
<textFieldExpression><![CDATA[$F{address_idaddress}]]></textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1"/>
</jr:column>
<jr:column width="200" uuid="36dc21c0-a551-4df8-a180-95cf5b9cfc0c">
<jr:tableHeader style="table_TH" height="30" rowSpan="1"/>
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="294719c1-d37b-4b53-ab0e-2045397c0d60"/>
<textFieldExpression><![CDATA[$F{address_city}]]></textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1"/>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
And the connection's config is this:
Note: Yes, the server has no password, it's just a testing environment...
Some attempts
I tried the other answers in the same post but none of them work for me. Last I tried changing the connection URL adding port and user but the error remains the same.
Don't know why below the <subDataset>
element I have the following XML:
<queryString>
<![CDATA[SELECT
*
FROM
`address` address
ORDER BY
city ASC]]>
</queryString>
<field name="idaddress" class="java.lang.Integer">
<fieldDescription><![CDATA[Address table ID]]></fieldDescription>
</field>
<field name="city" class="java.lang.String">
<fieldDescription><![CDATA[The city]]></fieldDescription>
</field>
<group name="city">
<groupExpression><![CDATA[$F{city}]]></groupExpression>
</group>
Looks the same as the <subDataset>
but it's there. I didn't wanted to remove as this is generated by iReport, so I assume it's correct.
So the question is: what am I missing here? What can I try to solve this? where can I look for some clue?
Thanks in advance for your answers.