Jump to content
Changes to the Jaspersoft community edition download ×
  • Use Case : Usage of two or more different data sources in Single Report


    Hi Folks,

     (Theory will update here later tomorrow or so, meanwhile use the JRXML to view the output)

    Data bases used : 
    1) MySQL , sakila db
    2) PostgreSQL foodmart db.

    Sample output



    Copy paste this code in your JRXML source code and observe the "Dataset1" data source parameters and connections as well the main report query and its connection.

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0  -->
    <!-- 2015-12-16T00:19:39 -->
    <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="MyFirst Report" pageWidth="610" pageHeight="842" columnWidth="570" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="295ab2d1-1932-4c33-823a-b088e233383f">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sakila - MySQL"/>
        <property name="com.jaspersoft.studio.unit." value="pixel"/>
        <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
        <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
        <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>
        <style name="Table 1_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 1_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 1_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="d0d375a4-ddad-4353-8013-29dd8f924ee6">
            <property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
            <queryString>
                <![CDATA[select * from customer  limit 10]]>
            </queryString>
            <field name="customer_id" class="java.lang.Integer"/>
            <field name="account_num" class="java.lang.Long"/>
            <field name="lname" class="java.lang.String"/>
            <field name="fname" class="java.lang.String"/>
        </subDataset>
        <parameter name="Parameter1" class="java.sql.Connection">
            <defaultValueExpression><![CDATA[java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/foodmart","postgres","postgres")]]></defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[select * from actor limit 5]]>
        </queryString>
        <field name="actor_id" class="java.lang.Integer">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="first_name" class="java.lang.String">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="last_name" class="java.lang.String">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="last_update" class="java.sql.Timestamp">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <title>
            <band height="30">
                <textField>
                    <reportElement mode="Opaque" x="0" y="0" width="555" height="30" forecolor="#FFFFFF" backcolor="#140AA6" uuid="b7e23fc2-6761-4e4c-9d81-3ed743736088"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Left" verticalAlignment="Middle">
                        <font size="12" isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Sample Data from MySQL (actors Table from Sakila DB) - Usal Grid Data"]]></textFieldExpression>
                </textField>
            </band>
        </title>
        <columnHeader>
            <band height="30">
                <staticText>
                    <reportElement x="0" y="0" width="141" height="30" uuid="3eb6afeb-84ce-43ec-89bb-12deef6ea8cc"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA[Actor ID]]></text>
                </staticText>
                <staticText>
                    <reportElement x="141" y="0" width="138" height="30" uuid="0447724f-01b9-467b-b63d-1cc3b32f21d9"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA[First Name]]></text>
                </staticText>
                <staticText>
                    <reportElement x="279" y="0" width="138" height="30" uuid="b6cb62b5-ca07-4059-b336-0d7bbc9c144d"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA[Last Name]]></text>
                </staticText>
                <staticText>
                    <reportElement x="417" y="0" width="138" height="30" uuid="f8e0ace8-5bda-4a21-8b6a-59a5ced2ab28"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font size="12" isBold="true"/>
                    </textElement>
                    <text><![CDATA[Last Update]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="30">
                <textField>
                    <reportElement x="0" y="0" width="141" height="30" uuid="1cc25a45-7e39-45d5-ba5a-d0fd7002f754"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                    <textFieldExpression><![CDATA[$F{actor_id}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="141" y="0" width="138" height="30" uuid="dac36d6a-dd6e-4733-b8a6-377fd5bceb81"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                    <textFieldExpression><![CDATA[$F{first_name}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="279" y="0" width="138" height="30" uuid="02859075-ae5d-4c2e-8a83-09fe29abb34c"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                    <textFieldExpression><![CDATA[$F{last_name}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="417" y="0" width="138" height="30" uuid="bffb90ed-fc35-41b4-a39b-fe28af23e307"/>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                    <textFieldExpression><![CDATA[$F{last_update}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <summary>
            <band height="100" splitType="Stretch">
                <componentElement>
                    <reportElement x="0" y="40" width="560" height="60" uuid="fdcac2e9-0944-42ed-bf44-7b73595775bf"/>
                    <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="70bb99c8-d50e-43df-a7da-9c4ad8b50ac8">
                            <datasetParameter name="REPORT_CONNECTION">
                                <datasetParameterExpression><![CDATA[java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/foodmart","postgres","postgres")]]></datasetParameterExpression>
                            </datasetParameter>
                        </datasetRun>
                        <jr:column width="130" uuid="b05aaed5-3d79-4bde-877e-c27574732176">
                            <jr:columnHeader style="Table 1_CH" height="30">
                                <staticText>
                                    <reportElement x="0" y="0" width="130" height="30" uuid="b06296b3-25a3-4ab5-8e07-8bb87252e358"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[Customer ID]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table 1_TD" height="30">
                                <textField>
                                    <reportElement x="0" y="0" width="130" height="30" uuid="491cf206-6da6-4935-9583-1bcd01b054ed"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{customer_id}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="130" uuid="0e829c3e-9ce9-413c-b7f7-5c422600915c">
                            <jr:columnHeader style="Table 1_CH" height="30">
                                <staticText>
                                    <reportElement x="0" y="0" width="130" height="30" uuid="e562ec15-d83d-4d24-ad05-8f9089e00417"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[Account Number]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table 1_TD" height="30">
                                <textField>
                                    <reportElement x="0" y="0" width="130" height="30" uuid="9f092a95-c914-4cb3-833a-0533262218e8"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{account_num}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="160" uuid="d6835cd4-c0c8-4572-9c1f-69757dae0058">
                            <jr:columnHeader style="Table 1_CH" height="30">
                                <staticText>
                                    <reportElement x="0" y="0" width="160" height="30" uuid="9740787e-699e-4bf6-afdb-8a42a9be401f"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[Last Name]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table 1_TD" height="30">
                                <textField>
                                    <reportElement x="0" y="0" width="160" height="30" uuid="aa773812-1211-458d-9db9-d6a2158b15d5"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{lname}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="140" uuid="66e70e1b-089b-4f37-abca-177c15501335">
                            <jr:columnHeader style="Table 1_CH" height="30">
                                <staticText>
                                    <reportElement x="0" y="0" width="140" height="30" uuid="6ad992bd-f73d-4d76-a641-e2b5c020f178"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle">
                                        <font size="12" isBold="true"/>
                                    </textElement>
                                    <text><![CDATA[First Name]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:detailCell style="Table 1_TD" height="30">
                                <textField>
                                    <reportElement x="0" y="0" width="140" height="30" uuid="490c9352-0017-47ba-a35d-03264e28682c"/>
                                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{fname}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                    </jr:table>
                </componentElement>
                <textField>
                    <reportElement mode="Opaque" x="0" y="15" width="560" height="25" forecolor="#FFFFFF" backcolor="#140AA6" uuid="e04d653c-7197-4ffe-8078-c70d101190b4">
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    </reportElement>
                    <box>
                        <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                        <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    </box>
                    <textElement textAlignment="Left" verticalAlignment="Middle">
                        <font size="12" isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Sample Data from PostgreSQL(customers table from foodmart DB) - Table Component"]]></textFieldExpression>
                </textField>
            </band>
        </summary>
    </jasperReport>


    How to get the same output in the Jasper Server ? 
    By creating Virtual Data source defined in Jasper Server and pointing out the report to use this data source.

    NOTE : Virtual Data source concept is an enterprise feature in Jaspersoft BI. 

    References : 
    http://community.jaspersoft.com/wiki/multiple-datasources-ireport-lists-tables-and-subreports
    http://community.jaspersoft.com/wiki/connecting-jasperreports-server-your-database




    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...