I have this JDBC SQL query:
select *
from table
where TX_DATE = {d '2009-01-05'} and TX_TIME = {t '15:23:39'}
This returns some rows. Note that, since Oracle has no TIME type, both columns are of type DATE.
But it fails when I use JDBC parameters:
select *
from table
where TX_DATE = ? and TX_TIME = ?
where the first parameter is new java.sql.Date(...)
and the second is new java.sql.Time(...)
. I print both parameters to stdout and they look good, so the values are correct. But I don't get any rows. Why? What's different between {t '15:23:39'}
and new java.sql.Time()
?
[EDIT] Here is the code that fills the PreparedStatement
:
public static void setParameters (final PreparedStatement stmt,
final Object... param)
{
for (int i=0; i<param.length; i++)
{
Object debug = param[i];
String type = null;
if (param[i] == null)
stmt.setString(i+1, null);
else if (param[i] instanceof java.sql.Time)
stmt.setTime (i+1, (java.sql.Time)param[i]);
I've set a breakpoint in setTime()
and it gets called. param[1].toString()
prints 15:23:39
, so I know the value is correct.
My guess is that since Oracle doesn't have a TIME type, there is a bug in the driver and the DATE part of the time is not ignored.
If I use select *
on the whole table, I get
TX_DATE TX_TIME
2009-01-08 2009-08-01
As you can seem, the time column is treated like a date by default. If I use TO_CHAR(TX_TIME, 'HH24:MI:SS')
, I get:
TX_DATE TX_TIME
2009-01-08 15:23:39
Where does 2009-08-01
come from?