Subreport with a csv file for datasource

0

Hello everyone,

I can't figure out how to insert a subreport with a csv file for datasource in a main report using an oracle connection.

Here is the csv file (link) used in the subreport :

<?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="ssrpprt_subreport3"
    pageWidth="555"
    pageHeight="802"
    columnWidth="555"
    leftMargin="0"
    rightMargin="0"
    topMargin="0" bottomMargin="0"
    uuid="c4179091-8dd0-4d56-a0f3-404727ec4126">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="PRENOM" class="java.lang.String"/>
    <field name="NOM" class="java.lang.String"/>
    <field name="VILLE" class="java.lang.String"/>
    <field name="EMAIL" class="java.lang.String"/>
    <field name="HEURES" class="java.lang.String"/>
    <field name="SALAIRE" class="java.lang.String"/>
    <columnHeader>
        <band height="26" splitType="Stretch">
            <staticText>
                <reportElement uuid="f0abaa4b-2663-4f7e-8e9a-f88b9e1e9bea" x="71" y="2" width="100" height="20"/>
                <textElement/>
                <text>
                    <![CDATA[NOM]]>
                </text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="1bc8b931-43fb-40dd-96f5-0377ec2919ed" x="71" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression>
                    <![CDATA[$F{NOM}]]>
                </textFieldExpression>
            </textField> 
        </band>
    </detail>
</jasperReport>

And here is the jrxml of the main report :

<?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="ssrpprt"
    pageWidth="842"
    pageHeight="595"
    orientation="Landscape"
    columnWidth="802"
    leftMargin="20"
    rightMargin="20"
    topMargin="20"
    bottomMargin="20"
    uuid="09d83108-ef1e-43af-87b2-a1891df92afa">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="ireport.jasperserver.reportUnit" value="/reports/leboucbe/test_sub"/>
    <property name="ireport.jasperserver.url" value="http://localhost:8081/jasperserver/services/repository"/>
    <style name="Crosstab Data Text" hAlign="Center"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression>
            <![CDATA["C:\\Users\\LEBOUCBE\\Documents\\Papirus\\"]]>
        </defaultValueExpression>
    </parameter>
    <parameter name="parameter2" class="net.sf.jasperreports.engine.data.JRCsvDataSource" isForPrompting="false">
        <defaultValueExpression>
            <![CDATA[new net.sf.jasperreports.engine.data.JRCsvDataSource(new File("C:\\Users\\LEBOUCBE\\Downloads\\dataJul-5-20132.csv"))]]>
        </defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[SELECT '2012' AS ANNEE_SUP FROM DUAL]]>
    </queryString>
    <field name="ANNEE_SUP" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader> <detail>
        <band height="125" splitType="Stretch">
            <subreport>
                <reportElement uuid="695e2eb5-62e5-4e6f-ae3c-8c7cb68c32f8" x="187" y="21" width="221" height="22"/>
                <dataSourceExpression>
                    <![CDATA[$P{parameter2}]]>
                </dataSourceExpression>
                <subreportExpression>
                    <![CDATA[$P{SUBREPORT_DIR} + "ssrpprt_subreport3.jasper"]]>
                </subreportExpression>
            </subreport>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

As you can see, my subreport connection type is set to Use a datasource expression and the Data Source expression is set to $P{parameter2}

My parameter2 class is set to net.sf.jasperreports.engine.data.JRCsvDataSource
and its value is set to new net.sf.jasperreports.engine.data.JRCsvDataSource(new File("C:\\Users\\me\\docs\\dataJul-5-20132.csv"))

when I try to compile the main report I get the following error :

Error filling print... net.sf.jasperreports.engine.JRException: Unknown column name : PRENOM
 
Setting up the file resolver...
Added file resolver...
net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Unknown column name : PRENOM
    at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:782)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:331)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:384)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:358)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2046)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:778)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:288)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
    at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
    at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: net.sf.jasperreports.engine.JRException: Unknown column name : PRENOM
    at net.sf.jasperreports.engine.data.JRCsvDataSource.getFieldValue(JRCsvDataSource.java:255)
    at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1331)
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1232)
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1208)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1554)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:655)
    at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59)
    at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:203)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
 
Print not filled. Try to use an
    EmptyDataSource...

Am I doing something wrong ?

thank's for your help

darky.ben's picture
Joined: Jun 6 2013 - 12:14am
Last seen: 6 years 1 month ago

2 Answers:

0

Hi Darky , 

I am facing exactly the same issue. 100% same and have tried the same way you tried but without any luck . Struggling to find an answers.

Did you manage to fix this ? Please share if you have any suggestions .

 

Regards,

Ankush

 

ankushchhabra's picture
Joined: Oct 7 2010 - 4:22am
Last seen: 5 months 3 weeks ago
0

Can you solve this problem?
I'm getting the same:

Error filling print... net.sf.jasperreports.engine.JRException: Unknown column name : SchemaGuid

Caused by: net.sf.jasperreports.engine.JRException: Unknown column name : SchemaGuid

 

Thanks

joniaraujo's picture
Joined: Jul 1 2014 - 3:12am
Last seen: 3 years 10 months ago

The name of the columns shoud be like
COLUMN_0
COLUMN_1
...
COLUMN_N

joniaraujo - 5 years 1 month ago
Feedback
randomness