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

Same day different hours, no result in query


ioanbalau
Go to solution Solved by ioanbalau,

Recommended Posts

Hi,

In Jasper Studio i have 2 input controls(both java.util.Date). If i try to Preview the report on the same day(Date from: 2017-10-17 02:00 Date To: 2017-10-17 23:00) it works properly.

But when i do the same from Java application the hours are not taken into consideration and result into an empty report.

If i select the Date From: 2017-10-17 02:00(today) and Date To: 2017-10-18 23:00 it gathers data between 2017-10-17 00:00 to  2017-10-18 00:00.

Condition in query: updatedtime between  $P{DateFromInputControl}  and $P{DateToInputControl}

Why hours are not taken into consideration?

Thank you,

Emi

 

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

kkrP36Query in report: select * from table a where b.updatedtime between $P{DateFromInputControl} and $P{DateToInputControl}

In Java i used JasperFillManager.fillReport() method. The input controls were formated to java.util.Date format

Definition in Jasper report:

<parameter name="DateFromInputControl" class="java.util.Date">
        <parameterDescription><![CDATA[]]></parameterDescription>
    </parameter>
    <parameter name="DateToInputControl" class="java.util.Date">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>

Link to image(calling in java): https://ibb.co/kkrP36

 

kkrP36

Link to comment
Share on other sites

Java code looks correct. I cant't see value $P{DateFromInputControl}

may by your code like this?
fillParams.put("DateFromInputControl", dateFrom);
fillParams.put("DateToInputControl", dateFrom);

Show declaration ( and new () ) for map fillParams and how you put values into this map in java code.
Why parameter names starting from upper letter?

Link to comment
Share on other sites

So definition of input parameters:

Map<String, Object> inputParameters = prepareInputParameters(inputControls);

Image before adding the new parameters:

Parameter 'DateFromInputControl': https://ibb.co/hezemR

Parameter 'DateToInputControl': https://ibb.co/gZMLt6

Function prepareInputParameters() returns a Map<String, Object> type(result):

result.put(parameterName, parameterValue);

return result;

After all the input controls were added: https://ibb.co/gzQ26R

 

Link to comment
Share on other sites

  • Solution

I found a solution for this. If the Input Parameter is java.util.Date type the hours are not taken into consideration in query(it gets only the date, at least from what i tested).

I changed the Input Parameter type to java.sql.Timestamp and now hours are taken into consideration.

Thank you!

Link to comment
Share on other sites

>> I found a solution for this. If the Input Parameter is java.util.Date type the hours are not taken into consideration in query
>> I changed the Input Parameter type to java.sql.Timestamp and now hours are taken into consideration.
It is not solution. You have to check your java code
I make test report and it work fine with java.util.Date. My test report shows parameters in title of report with hours !=0. And it uses hours in query correctly

You have a chance get unexpected errors because your solution hide potentional errors (types casting?, parsing?, ...?)
I hope you will find a time to solve this problem in right way.
Good luck

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