I have a query as below:
SELECT COL1, COL2 FROM SCHEM1.TAB1 WHERE COL3=? AND COL4=?
I am executing above query in my java class as:
List<Map<String, Object>> resultList = jdbcTemplate.queryForList(sql, (Object[]) queryParams);
Issue is I am getting queryParams
at runtime from a text properties file as below:
2013-03-28||helloWorld
As seen in above line, the properties file has arguments to a sql. All arguments are delimited by a double pipe.
I am reading this line into a String[]
by using the split method on the pipe delimiter.
So my resultant queryParams
String array would be:
String[]
queryParams
where String[0]
would be 2013-03-28
and String[1]
would be helloWorld
When I am passing this String[]
directly to templates queryForList
method by casting it as Object[]
as mentioned at the start of this post, and when my log4j is set to debug
mode, I am getting termination on the following error:
Exception in thread "main" java.lang.Error: SQLWarning chain holds value that is not a SQLWarning
at java.sql.SQLWarning.getNextWarning(SQLWarning.java:91)
at org.springframework.jdbc.core.JdbcTemplate.handleWarnings(JdbcTemplate.java:1260)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:713)
at org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:796)
at com.hsbc.pb.it.re.db.dao.impl.ReconDaoImplNew.getColumnList(MyClass.java:362)
A line just above this error in the console mentions:
SQLWarning ignored: SQL state 'null', error code '0', message [Input data type mismatch, see chained exceptions; will retry execution using describe input information. Please change application to use an input data type that matches the database column type as required by JDBC semantics.]
However, this code works correctly when I am setting the log4j level to info
.
What is the cause of this termination ?
How to resolve it ?
Is it to do with parameter type (as in, I am passing String to queryForList when the expected column is Date) ? If so, how can I correctly format a String to expected type before passing to queryForList
method ?
I can change the properties file to something like:
2013-06-28,DATE||helloWorld,VARCHAR
Where information on the type of the value is also passed along. But using this info, how can I convert the String to given type -- Is such approach a nice solution ?
Why the error is not coming when log4j is in info
mode ?
Thanks for reading!
Please let me know if any details are missing.