Jump to content
Changes to the Jaspersoft community edition download ×

How to display a simple table in Jaspersoft Studio?


Recommended Posts

I must be doing something seriously wrong but I cannot get Jasper Reports to display a simple table displaying the results of a database query. 

I have a table in the database that I am accessing via HQL "from com.jasper.Order" - the table has two columns orderId & orderDate. 

All I want to do is to display a table in the report showing the Orders in the database.  

The jrxml looks like this

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  --><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="TSC-D6" pageWidth="1395" pageHeight="842" columnWidth="1300" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5d0c2737-81b8-4926-a590-1485435fda4a">    <property name="ireport.zoom" value="2.0"/>    <property name="ireport.x" value="0"/>    <property name="ireport.y" value="0"/>    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Order_DataAdapter.xml"/>    <subDataset name="ProductOrder" uuid="0bca6349-f6da-4944-8a18-621d46be4dbd">        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Order_DataAdapter.xml"/>        <queryString language="hql">            <![CDATA[from com.jasper.Order]]>        </queryString>        <field name="orderId" class="java.lang.String">            <fieldDescription><![CDATA[orderId]]></fieldDescription>        </field>        <field name="orderDate" class="java.util.Date">            <fieldDescription><![CDATA[orderDate]]></fieldDescription>        </field>    </subDataset>    <queryString language="sql">        <![CDATA[select 1 from dual]]>    </queryString>    <summary>        <band height="155">            <componentElement>                <reportElement x="10" y="20" width="220" height="80" uuid="2d0a50a3-0cbf-4b6a-b4b5-62feafa59ab6">                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>                    <property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>                </reportElement>                <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="ProductOrder" uuid="e3927875-e4e2-4de3-bdd9-f280035571e5"/>                    <jr:column width="140" uuid="6da3aa43-030a-4715-bb5c-c490fdc2d4b2">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>                        <jr:columnHeader height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="140" height="30" uuid="e2b85196-002e-41d4-9cc2-20782d811027"/>                                <text><![CDATA[Order Date]]></text>                            </staticText>                        </jr:columnHeader>                        <jr:detailCell height="30">                            <textField>                                <reportElement x="0" y="0" width="140" height="30" uuid="b10f909e-6ca0-4267-9ae5-e5aa88d341a9"/>                                <textFieldExpression><![CDATA[$F{orderDate}]]></textFieldExpression>                            </textField>                        </jr:detailCell>                    </jr:column>                    <jr:column width="130" uuid="149ef200-8042-4830-8f99-ff9cfcc60789">                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>                        <jr:columnHeader height="30" rowSpan="1">                            <staticText>                                <reportElement x="0" y="0" width="130" height="30" uuid="7d29bece-47e3-4baa-854e-061c2a2117da"/>                                <text><![CDATA[Order Id]]></text>                            </staticText>                        </jr:columnHeader>                        <jr:detailCell height="30">                            <staticText>                                <reportElement x="0" y="0" width="130" height="30" uuid="90179672-d45f-497a-980e-c3acea61eee7"/>                                <text><![CDATA[OrderId]]></text>                            </staticText>                        </jr:detailCell>                    </jr:column>                </jr:table>            </componentElement>            <textField pattern="dd/MM/yyyy">                <reportElement x="70" y="115" width="72" height="15" uuid="95a65977-a12f-467f-a1b0-8d6c13baa123"/>                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>            </textField>            <staticText>                <reportElement x="7" y="115" width="63" height="15" isPrintInFirstWholeBand="true" uuid="495a2de9-f164-449f-a053-c12b88733d16"/>                <text><![CDATA[Report Date    :]]></text>            </staticText>        </band>    </summary></jasperReport>[/code]

The Order_DataAdapter.xml returns a Collection of Java Beans with test data. The data adapter does work as I can use it to display data if the add fields to a details band in a different report & viewed one order page per order.  

But when I preview the report with the table - it always comes back blank.

I have tried running the report in my application using the hibernate connection & again the report comes back empty. If I run the page per order report everything works okay. 

But I dont want to display each Order in a separate page - I just want a simple table to display all my Orders. I have tried numerous combinations to get the table in the report to work but I am getting nowwhere, it may soon be time to try a different reporting framework....



Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic


I feel your pain. Looking at my crib notes, I always have to right click on the subdata set (i.e. ProductOrders in your case) and click 'Connect to Main dataset'.

I don't think that is your exact problem but I do think it's someting to do with the data connection. If you add the 'dataSourceExpression' tag into your  'datasetRun' statement (see below) the table starts to fire (i.e. the headings start to appear).

                    <datasetRun subDataset="ProductOrder" uuid="f5c23ded-3385-4dca-b61a-2fc9c51fa814">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource() ]]></dataSourceExpression>

Sorry I can't be more help but hopefully nudging you in the right direction.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...