Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:13:19+00:00 2026-05-25T18:13:19+00:00

Until now I have always been constrained by one thing with jasper-reports. I can

  • 0

Until now I have always been constrained by one thing with jasper-reports.
I can only write one data query in each document.
When I need to write another query I must create a subreport, pass its needed parameters and so on.

But I’m definitely not convinced that it’s the good way to do it.

So is there another way to fire multiple data queries in a single jasper document?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:13:19+00:00Added an answer on May 25, 2026 at 6:13 pm

    It is possible to use execute multiple queries from a single report by using a subDataset and datasetRun. The behaviour is like having one or more subreports embedded into a single report file.

    Define a subDataset like this:

    <subDataset name="dataset1">
        <parameter name="someParam" class="java.lang.String"/>
        <queryString><![CDATA[SELECT column1, column2 FROM table1 WHERE column1=$P!{someParam}]]></queryString>
        <field name="column1" class="java.lang.String"/>
        <field name="column2" class="java.lang.String"/>
    </subDataset>
    

    Subdatasets can have parameters, fields, variables and groups just like a report can. Each subdataset can have it’s own query, and the report can have as many subdatasets as you want.

    To use a subdataset, you need to define a datasetRun. This can only be done inside particular elements: charts, crosstabs, tables and lists. We will use a list as it behaves almost exactly like another detail band.

    This code defines a list that uses our subdataset:

    <componentElement>
        <reportElement x="0" y="0" width="100" height="40"/>
        <jr:list 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">
                <datasetParameter name="someParam"><datasetParameterExpression><![CDATA["some value for column 1"]]></datasetParameterExpression></datasetParameter>
            </datasetRun>
            <jr:listContents height="40">
                <textField>
                    <reportElement x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.String"><![CDATA[$F{column1}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="0" y="20" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression class="java.lang.String"><![CDATA[$F{column2}]]></textFieldExpression>
                </textField>
            </jr:listContents>
        </jr:list>
    </componentElement>
    

    Some notes:

    • The jr:listContents element is analogous to a detail band element. You can place almost any other elements inside.

    • The datasetRun element is much like a subreport element. It can have a dataSourceExpression or connectionExpression inside, which will change where the data comes from. If neither of these are present, the report datasource is used.

    • The same subDataset can be used by many datasetRuns, so you can easily run a query multiple times with different parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a js function which has, until now, always been the callback for
Up until now, I have always been using JSP to display pages. When a
I'm a ClearCase newbie and up until now have been used to SVN. Therefore,
Up until now I have been using std::string in my C++ applications for embedded
I came across this recently, up until now I have been happily overriding the
From the .net 4.0 previews I have read until now there has been lots
I have a list of elements, and I've been using will_paginate up until now,
Up until now, my experience with databases has always been working with an intermediate
I am new to installers and up until now have just been manually executing
Greetings good people - I need some help. I have until now buildt web-pages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.