There are cases where you will need both custom datasources for your master report and a simple one stage sql query in your subreport. So how do you tell IReport just to use a simple JDBC connection?

In order to tell IReport you want to use a simple JDBC connection, right click on the subreport block in the GUI, from the master report.

Choose properties.

Click on the Subreport tab.

For the connection/Datasource expression choose:
Use connection expressionIn the expression editor box use this expression:

DriverManager.getConnection(”URL”, “username”, “password”)

Where the URL, username, and password are specific for your database. The quotes MUST be included.

Click apply on your expression editor, and close the subreport’s property box. Now we must add an import statement to the report’s .jrxml file. Go to edit, xml source. In your editor you must add this line to the import statements near the top of file:

<import value=”java.sql.*”>

Save your report. If your connection parameters are right, your subreport should be filled from your jdbc connection.

Make sure you remember to change these JDBC parameters when you move the subreport to your test and production environments!