1

I have SELECT queries where a parameter is a Java Date. There is no error in the console but they do not get data from the database.

First query:

<select id="getByDate" parameterType="java.util.Date" resultType="domain.Book">
SELECT * FROM BOOK WHERE DTCREATED = #{dateCreated}
</select>

I tried also _date for parameterType, the same happened. My other queries use map for parameterType since number of parameters are either 2 or 3.

Again, there is no error. Just no data being returned. For non-Date parameter, queries are working.

Any help would be appreciated. Thank you.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Julez
  • 1,010
  • 22
  • 44
  • 1
    It might be that you face the issue with precision of date vs timestamp https://stackoverflow.com/questions/6612679/non-negligible-execution-plan-difference-with-oracle-when-using-jdbc-timestamp-o. See https://blog.jooq.org/2014/12/22/are-you-binding-your-oracle-dates-correctly-i-bet-you-arent/ for more details – Roman-Stop RU aggression in UA Oct 31 '18 at 17:49
  • java.util.Date s are really just instants in milliseconds. Might work if you switch the type to java.sql.Date – brt Oct 31 '18 at 20:40
  • @brt I switched the type to java.sql.Date: java.util.Date cannot be cast to java.sql.Date – Julez Nov 05 '18 at 03:16
  • @JulezJupiter You'll need to switch the parameterType as well as the field in your java class. Just for testing, you could switch your WHERE clause to `DTCREATED > #{dateCreated}` or `DTCREATED < #{dateCreated}` just to see if you get any rows. – brt Nov 05 '18 at 16:37
  • @Julez hi, are you able to solve your issue? i having it now. I still unable to solve it, altho if i put ">" it is able to come out, but i want it to be "=". – SicaYoumi Apr 20 '20 at 15:28

0 Answers0