cancel
Showing results for 
Search instead for 
Did you mean: 

Passing datetime parameters to CR from Java application

Former Member
0 Kudos

Hi,

I have created a Java application, which takes in some command line arguments (such as DB name, user id, pwd, report name and other parameters) and connects to the report, refreshes it based on the given parameters, and exports to a rpt.

It works great as long as I pass only String parameters, I encounter a problem while passing date parameters to this report. I follow the code given in the sample applications on this site.

Calendar calendar = Calendar.getInstance();

calendar.set(2001,9,31,0,0,0);

Date dateValue = calendar.getTime();

System.out.println(dateValue.toString());

repDoc.getReportSource().refresh();

repDoc.verifyDatabase();

paramFieldController.setCurrentValue("", "Param1", dateValue);

The problem is that the exported report has no data in it. However, when I refresh it using current parameters, it loads data from the server.

1. As I said, the app works fine when I'm using String parameters, so it is not a DB connection problem.

2. I think the parameter is being passed correctly, which is why I find data in the report if I refresh it without changing the parameters.

Has anyone encountered this before? Any help would be appreciated.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You're refreshing before setting parameter field values.

I would check out the sample code here:

http://diamond.businessobjects.com/node/5854

Sincerely,

Ted Ueda

Former Member
0 Kudos

Hi, Thanks for the reply.

However, when i put the refresh code below the setCurrentValue method, I get the following error:

com.crystaldecisions.reports.exportinterface.exceptions.ExportException: Some parameters are missing values

I think the parameters have to be set after telling CR to refresh. Also, the sample application you provided does not refresh the report at all. So I tried it without using the refresh, and it still works the same way.

And, as I mentioned, this code works fine with String parameters, refreshing and all. Even If my report has no data saved initially, the exported report contains the values I expect based on the parameters I give. Just that if I use date parameters, I end up with a blank report.

Let me explain further. When I open this exported blank report using CR and check the current parameter values, they have been set correctly. Then, If I refresh it using current parameter values in CR, i get a pop up saying 'The database has changed. Proceeding to fix up the report'. And then the values show up correct.

Thanks for your time.

Former Member
0 Kudos

You don't need the refresh() on the ReportSource.

When you state that the report doesn't refresh, are you saying that the parameter values as set in the code doesn't show up in the displayed report, or that you couldn't find the refresh() method anywhere in the code? Again, you don't need the refresh().

That you're getting the 'The database has changed. Proceeding to fix up the report.' indicates something fundamental has changed in the schema as represented in the report.

What type of connectivity are you using?

Sincerely,

Ted Ueda

Former Member
0 Kudos

I understood that I don't need the refresh().

The report when created, was created using an OLE DB source, connecting to an oracle db. I use the program to change the datasource to jdbc:oracle:oci at runtime, before passing parameters and exporting.

Thanks.

Former Member
0 Kudos

Ok - so you're changing the driver using the JRC before running the report and exporting.

One thing to check is that the expected SQL statement is being sent to the RDBMs - I'm assuming you're using the Date to filter records.

The SQL being sent to the RDBMs is logged if you turn on Log4J - there should be a sample log4j.properties file with the JRC, and you can specify DEBUG logging level, and save to a file.

That's the first thing I would check.

Also - I would ensure you have the latest JRC - it's the one included with Crystal Reports for Eclipse - Version 1, Patch 5 as of today.

Sincerely,

Ted Ueda

Former Member
0 Kudos

Finally got it working correctly. I used the log4j logs to see the values being passed, as you suggested. The problem was that java was adding an arbitrary number of milliseconds to the datetime that I was sending over.

Just had to set the milliseconds to 0 to get this to work. Thanks a lot for your help.

Former Member
0 Kudos

I'm heartened to hear that that's working.

The millisecond thing is something encountered by others as well - it's something that trips up Java programmers often.

For others reading this thread, when retrieving java.util.Date from a java.util.Calendar, it's recommended to invoke clear() on the Calendar object, to clear all fields, including the millisecond one. Otherwise, the fields are filled with the current time when the Calendar object is created (down to millisecond granularity).

Sincerely,

Ted Ueda

Answers (0)