Jump to content
We've recently updated our Privacy Statement, available here ×

One report - multiple JDBC datasources


mdaleiden

Recommended Posts

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

  • 5 years later...

Hi,

I have a similar question: I have 3 databases (dev, acc and live) and I want to run one and the same report 3 times but with the different DB connection. Is there a simple solution for this ?

I do not want to make 3 copies where only the data source is different.

Any ideas ?

Thanks.

 

Link to comment
Share on other sites

Hello.

 

Thanks for the answer.

I was also thinking about using a parameter but the problem is I do not know how to use the value of the parameter to specify which database to use.

There are 2 parameters REPORT_CONNECTION and REPORT_DATASOURCE but they are read only.


Regards,

Patrick

Link to comment
Share on other sites

Hi Patrick,

Using JR builtin parameters has no meaning here. In such a case you only need a method/procedure to collect the parametrized user input before filling the report. Then you can choose your connection depending on this param value.

Hope this helps,

sanda

Code:
public String getUserConnectionType(){  String user_option = "dev";    // detect the option chosen by the user here   return user_option;}at fill time:Connection conn = getUserConnectionType().equals("acc") ? getAccConnection() : (getUserConnectionType().equals("live") ?  getLiveConnection() : getDevConnection())JasperFillManager.fillReportToFile(the_report, parameters_map, conn);
Link to comment
Share on other sites

  • 2 weeks later...

Thanks.

As far as I understand is this only possible when calling the report from Java code, is that right ?

I want to set the connection within iReport, maybe in a scriptlet ?

The strange thing is that I have to use fillReportToFile since I am in the report file (in iReport).

I am not so familiar with scriptlets.


Patrick

Link to comment
Share on other sites

Patrick, your last reply added a new and interesting element to our discussion: the iReport tool. If you are running reports from within iReport only, hardcoding connections in java is no more necessary.

Until you wrote about the iReport here, I was convinced that your report is probably running from within a java/web application that has to distinguish between various user input. In this case, in my opinion, establishing different db connections at design time is not possible, so the most common solution relies on writing a piece of java code in the java app. At the moment I'm not sure if it's possible to choose between data sources using a scriptlet, but maybe someone else could provide a clue here.

Things are a lot simplified if you are running the report from iReport only. In this case you have to define 3 different data sources in iReport (the dev, acc and live ds) and, when running the report, just select the desired data source from the available data sources list before clicking the preview button. That's all. There's no java code to be written, no parameters to be set, because iReport does it for you.

Kind regards,

sanda
 

Link to comment
Share on other sites

Hi Sanda,

 

I am afraid I did not explain it too well, sorry.

First of all I understand what you mean with the example code by using the FillReport method.

Whenever I want to start the reports from a Java program I can use it but that is not the case.

I want to run the reports from a web server but I want to have 1 report for all the three environments (dev, acc, live) where I can select the required DB.

Now I have 3 copies of the reports on my Jaspersoft server and I specify the DB at the properties level of each report.

I want to have for instance the possibility at startup of the report to select the environment and this selection causes to set the correct DB, that is what I meant within iReport.


Regards,

Patrick

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...