1

I am evaluating JasperReports and Jaspersoft Studio for using in the company I work for and I am trying to build a report that contains information from 2 different databases.

I have 2 data adapters configured.

I've my research and found out that the only way to do so is to have either a list, table or subreport in a main report, but I still can't make it work.

I took the subreport approach, I have two reports that work separately, the main one executes this query in the sample DB

select 1 from ORDERS limit 10

The subreport runs this one in a Vertica database I own:

select 1 from my_schema.my_table limit 10

Both of them, as said, run separately.

So I go to the mainreport and add a SubReport element to the ColumnHeader band, then the wizard opens:

  • In the step 1 I select the subreport from the project
  • Second step is connection. I have these options:
    • Same JDBC conection
    • Use another connection
    • Use an empty data source
    • Use a JRDatasourceExpression
    • Don't use any connection.

The first and third ones are not what I want.

I tried to set the second one, but I could not find a way to select the data adapter that I have configured.

The last one doesn't work ( I get a message saying that my_schema doesn't exists, so I think that it is still trying to access the MainReport database).

Is there anyway I can make a subreport run a query in a different database/datasource from the main report?

Alex K
  • 22,315
  • 19
  • 108
  • 236
JSBach
  • 4,679
  • 8
  • 51
  • 98
  • Possible duplicate of [Multiple queries in a single jasper document](http://stackoverflow.com/questions/7482412/multiple-queries-in-a-single-jasper-document) – Alex K Jul 02 '16 at 22:03

3 Answers3

1

I can summarize what I did if anyone has the same issue:

I made a proof of concept (therefore I do not have the code anymore), but I created a JRDataSource class using this tutorial and there I manually access the database and returned the rows. Then I use this as the datasource of my subreport/table. Not as nice as I wanted, but it is possible

JSBach
  • 4,679
  • 8
  • 51
  • 98
0

I guess this iReport article is also applicable to reports designed in jaspersoft studio; you just need to define the subreport connection parameter with the given expression.

  • Hi, I've seen it. But if you take a look at the tags, one of them is "OBSOLETE" :( – JSBach Jul 28 '15 at 08:35
  • 1
    The technique is not obsolete as of JasperReports 6.1 API, however they are leaving iReport and thus may be obsolete. Programmatically speaking, this is the same thing to do for me if I needed to do it inside my program. – Turan Yüksel Jul 28 '15 at 09:59
  • 1
    Before noticing the obsolete tag I tried this article, but Jasper Studio didn't recognize the $P{SUBREPORT_CONNECTION} parameter – JSBach Jul 28 '15 at 10:13
0

Perhaps, you can ask for help from two parameters which defined in the master report by yourself. Such as:

  1. $P{MySubreport} with type net.sf.jasperreport.engine.JasperReport;

  2. $P{MyDatasource} with type net.sf.jasperreport.engine.JRDataSource;

  3. Associate these two parameters to your subreport element respectively in attributes 'Expression' and 'Data Source Expression';

Please write your DataSource class that implements interface JRDataSource. Then, in your servlet class, put your real parameter values(JasperReport for your subreport .jasper file, and your DataSource object) into a parameters Map object, and call JasperFillManager.fillReport().

Anh Pham
  • 2,108
  • 9
  • 18
  • 29
Jacky
  • 1
  • 1