I am using spring JDBCTemplate to query my data.
I have the following query in my code
static final String SQL = SELECT msgs.msg_submit_date MSG_DATE FROM {0}.messages msgs
WHERE TRUNC(msgs.msg_submit_date)
BETWEEN TO_DATE(:startDate,'YYYY-MM-DD') AND TO_DATE(:endDate,'YYYY-MM-DD') ;
String formattedSQL = MessageFormat.format(SQL , new Object[] "sms.schema"});
and I am getting an ORA-00904: "DD": invalid identifier error when I run it. I am assuming this is because the msg_submit_date column has HH:MI:SS associated with it, however, I don't want to place HH:MI:SS in my java code. Having year, month and day will suffice.
Also, when I run the same query, in my Oracle SQL Developer IDE, it runs fine without any errors so not sure what is going wrong.
The date gets generated via java.time.LocalDate using the following format:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/d/yyyy");
which returns the following string format 2018-06-03.
The jdbc call:
jdbcTemplate.query(formattedSQL, params, new MessagesRowMapper())
I think it maybe due to MessageFormat.
ofPattern()match theto_date()pattern; and why are you passing strings instead of binding dates directly - doesn't Spring allow that?)formattedSQL? How do you pass the values? Where is the code of the row mapper?