java - Unable to query on date condition in specific range -


i want fetch record hsql database , query below:

ao.find(issueda.class, query.select().where("user=? , to_date(start_time, 'yyyy/mm/dd')>=     to_date(?,'yyyy/mm/dd') , to_date(end_time, 'yyyy/mm/dd') <= to_date(?,'yyyy/mm/dd')",user,parseddate,parseddate)) 

now, gives me error "to_date" not valid keyword below:

at java.lang.thread.run(thread.java:662)  caused by: java.sql.sqlexception: unexpected token: to_date in statement [select *     public.ao_0371a8_issue_da user=? , to_date(start_time, 'yyyy/mm/dd')>= to_date(?,'yyyy/mm/dd') ,    to_date(end_time, 'yyyy/mm/dd') <= to_date(?,'yyyy/mm/dd')] 

if remove "to_date" not getting correct result data data , return null though data existed in database. in database date field value's format "2013-05-15 00:00:00.000000000"

can 1 plz share me alternative query database ??

you don't need to_date query. to_date converting dates in string format.

it seems comments want 1 parameter between 2 dates, or outside 2 dates.

the correct sql type of query this:

this returns dates between start , end, inclusive:

where user=? , ? between cast(start_time date) , cast(end_time date) 

this returns dates outside start , end:

where user=? , ? not between cast(start_time date) , cast(end_time date) 

for above queries, use java.sql.data object preparedstatement.setdate(colindex)

now if date want compare string in format such '2013/05/20' need to_date(?,'yyyy/mm/dd') instead of parameter. if date string in standard format such '2013-05-20' can use cast(? date) instead of parameter.

i assume database table columns start_time , end_time defined of timestamp type, should work varchar(n) or char(n) types.


Comments