spring jdbctemplate: different behaviour on different app servers (date issue)
I am running the same select query on the same database using the same code but using 2 different app servers.
Query: Find a certian day's entries in a journal.
1) Existing legacy app server (BroadVision running on unix): Select title, content from journal where entry_date = TO_DATE(?, 'DD/MM/YY HH24:MI:SS');
DEBUG:core.StatementCreatorUtils:Setting SQL statement parameter value: column index 1, parameter value [Thu Sep 29 14:32:58 IST 2011], value class [java.util.Date], SQL type unknown
This works fine
2) JBoss app server (Running on windows): Select title, content from journal where entry_date = TO_DATE(?, 'DD/MM/YY HH24:MI:SS');
DEBUG:core.StatementCreatorUtils:Setting SQL statement parameter value: c开发者_运维百科olumn index 1, parameter value [Thu Sep 29 14:41:26 IST 2011], value class [java.util.Date], SQL type unknown
ORA-01858: a non-numeric character was found where a numeric was expected
Any ideas how to get this running on the JBoss app?
Thanks,
Kenny
The code seems incorrect to me. The TO_DATE
function's goal is to transform a string in a given format into a date. And you're not passing a string as argument to this function, but a java.util.Date
object.
You should remove the use of the TO_DATE
function, transform your java.util.Date
into a java.sql.Timestamp
object, and use setTimestamp
to pass the argument to your prepared statement.
The fact that it worked as is on your unix box looks like an accident to me.
精彩评论