java - Oracle type DATE -


i have field type date in database table

i need select information date range:

select  to_char(log_hour, ' dd/mm/yy hh24')   log_hourly_page page_counts to_char(log_hour, 'dd/mm/yy') = '25/06/13'  order log_hour desc;  

and getting right results (many records each hour)

 25/06/13 23  25/06/13 23  25/06/13 23  25/06/13 22  ...........   25/06/13 04  25/06/13 04  25/06/13 00  25/06/13 00 

but when run

select  to_char(log_hour, ' dd/mm/yy hh24')   log_hourly_page page_counts log_hour = '25-jun-2013'  order log_hour desc; 

i 0 hour,

 25/06/13 00  25/06/13 00  25/06/13 00  25/06/13 00 .............  25/06/13 00  25/06/13 00  25/06/13 00 

why second query works way? testing query since pass java.util.date object date , returns wrong data, 00 hour.

there time component date specified in way in oracle:

'25-jun-2013' 

and time component 0 (midnight), , hour 0, matches specific point in time, , not whole day.

to entire day's range, use have:

where to_char(log_hour, 'dd/mm/yy') = '25/06/13' 

or use range:

where log_hour >= '25/06/13' , log_hour < '26/06/13' 

edit

now see actual java code:

query.setdate("date", date); 

that passes sql date has no time component.

you want use settimestamp, passes sql timestamp database, has time component date component.

query.settimestamp("date", timestamp); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -