未设置查询语言:为什么在使用 csv 数据适配器时会出现此错误?

Query language not set: Why am I getting this error in case using csv data adapter?

我已将数据源配置为 csv 文件。配置的源如下所示:

然后我创建一个空的报告模板并添加一个 table 具有相同的数据源:

添加了table,如下所示:

但是当我尝试预览时,我收到一条错误消息:

我只是不明白这是为什么。我该如何解决这个问题?

这是 jrxml:

 <?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="Blank_Letter" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="445d22e8-c434-459d-9696-8f6167fa66e5">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
    <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
            <topPen lineWidth="0.5" lineColor="#000000"/>
            <leftPen lineWidth="0.5" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineColor="#000000"/>
            <rightPen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Dataset1" uuid="43a885cc-1f9a-413f-a114-e5e0e287ffec">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="Name" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="Name" class="java.lang.String"/>
    <detail>
        <band height="332" splitType="Stretch">
            <componentElement>
                <reportElement x="207" y="132" width="200" height="200" uuid="ec75e03d-be8f-4abb-be6c-29c86cc6f2b9"/>
                <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="Dataset1" uuid="ae4afac3-2a54-4e7c-a3cd-c8a246f79ec4">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION} ]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="200" uuid="8d7d6c5b-2448-486d-a1e3-0a4d9e5f40a3">
                        <jr:columnHeader style="Table_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="200" height="30" uuid="aabc6fa0-086b-4bba-b92c-79c0a3467048"/>
                                <text><![CDATA[Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="200" height="30" uuid="783860ab-a9f1-402c-ab54-fa056bd29350"/>
                                <textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

我的 csv 看起来像这样:

Name,ID
Daphne Kub,1
Karolann Lebsack,2
Charlotte Parisian,3
Jairo Mayert,4

如果我可以添加更多输入,请告诉我。

怎么了?

你犯了很多错误。

  1. 您必须将 table 组件移动到 标题Summary band,因为您仅使用 Dataset1 子数据集,而不是主数据集。

  2. 您可以将 $P{REPORT_DATA_SOURCE} 传递给 dataSourceExpression

工作示例

你甚至不需要声明主数据集(我在这个例子中删除了它)。

jrxml会是这样的:

<?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="Blank_Letter" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="445d22e8-c434-459d-9696-8f6167fa66e5">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
    <subDataset name="Dataset1" uuid="43a885cc-1f9a-413f-a114-e5e0e287ffec">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="Name" class="java.lang.String"/>
    </subDataset>
    <title>
        <band height="60" splitType="Stretch">
            <componentElement>
                <reportElement x="180" y="0" width="200" height="60" uuid="ec75e03d-be8f-4abb-be6c-29c86cc6f2b9"/>
                <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="Dataset1" uuid="85f0f7ec-24c1-49f2-bde8-0287a608d0e0">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="200" uuid="8d7d6c5b-2448-486d-a1e3-0a4d9e5f40a3">
                        <jr:columnHeader height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="200" height="30" uuid="aabc6fa0-086b-4bba-b92c-79c0a3467048"/>
                                <text><![CDATA[Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="200" height="30" uuid="783860ab-a9f1-402c-ab54-fa056bd29350"/>
                                <textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </title>
</jasperReport>

JSS 的结果将是: