title: JDBC: How can I query by time in Oracle?
body: <p>I have this JDBC SQL query:</p>
  
  <pre><code>select *
  from table
  where TX_DATE = {d '2009-01-05'} and TX_TIME = {t '15:23:39'}
  </code></pre>
  
  <p>This returns some rows. Note that, since Oracle has no TIME type, both columns are of type DATE.</p>
  
  <p>But it fails when I use JDBC parameters:</p>
  
  <pre><code>select *
  from table
  where TX_DATE = ? and TX_TIME = ?
  </code></pre>
  
  <p>where the first parameter is <code>new java.sql.Date(...)</code> and the second is <code>new java.sql.Time(...)</code>. 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 <code>{t '15:23:39'}</code> and <code>new java.sql.Time()</code>?</p>
  
  <p>[EDIT] Here is the code that fills the <code>PreparedStatement</code>:</p>
  
  <pre><code>public static void setParameters (final PreparedStatement stmt,
          final Object... param)
  {
      for (int i=0; i&lt;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]);
  </code></pre>
  
  <p>I've set a breakpoint in <code>setTime()</code> and it gets called. <code>param[1].toString()</code> prints <code>15:23:39</code>, so I know the value is correct.</p>
  
  <p>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.</p>
  
  <p>If I use <code>select *</code> on the whole table, I get</p>
  
  <pre><code>TX_DATE     TX_TIME
  2009-01-08  2009-08-01
  </code></pre>
  
  <p>As you can seem, the time column is treated like a date by default. If I use <code>TO_CHAR(TX_TIME, 'HH24:MI:SS')</code>, I get:</p>
  
  <pre><code>TX_DATE     TX_TIME
  2009-01-08  15:23:39
  </code></pre>
  
  <p>Where does <code>2009-08-01</code> come from?</p>