Avoiding quote insertion on NamedParameterJdbcTemplate parameterized query

238 Views Asked by At

thank you for taking the time to read.

I am trying to execute a query using a JDBC connection to Snowflake via this line of code:

namedParamJdbcTemplate.execute(sqlQuery, paramKeyValueMap, (PreparedStatementCallback) ps -> ps.executeUpdate());

Here are the variables being passed to the execute method:

query = 'SELECT TYPE_ID, DESCRIPTION FROM LATEST.ACCOUNT_TYPE
                    WHERE DESCRIPTION IN (''AWARD'',''CONSUMER_DDA'')
                    AND SYS_SRC_OP_TIMESTAMP > :SYS_SRC_OP_TIMESTAMP'

paramKeyValueMap = ('SYS_SRC_OP_TIMESTAMP' --> 'CURRENT_DATE-365')

Unfortunately, this is throwing a SQL error:

Timestamp 'CURRENT_DATE-365' is not recognized; nested exception is net.snowflake.client.jdbc.SnowflakeSQLException: Timestamp 'CURRENT_DATE-365' is not recognized

As you can see, the error is that one of the parameters being passed to the query, <CURRENT_DATE-365> is being surrounded by quotes during runtime execution.

I tried manually executing the query without the quotes and it appears to work correctly.

Please let me know if you are aware of a way to pass parameters without the quotes.

Respectfully, mark

0

There are 0 best solutions below