jeudi 16 avril 2015

DB2 sql error code -245 for a date

I am reading several sql queries from database inside a loop as below:



{ // start of loop
Map<String, Object> queryRS = this.jdbcTemplate.queryForMap(this.querySql,queryParam);
String query = (String) queryRS.get("QUERY");

// code here as explained below

} // end of loop


The query returned could have any number of parameters. However, in all of them I have to set same date as the parameter.


For this I am counting the number of occurrence of character ? in the query and creating an Object array with same date repeated as below.



String date = '2010-12-31';
int numArgs = StringUtils.countMatches(query, "?");
String[] paramArgs = new String[numArgs];
for (int i = 0; i < numArgs; i++) {
paramArgs[i] = date;
}


After which I am executing the query as below:



SqlRowSet myRowSet = this.jdbcTemplate.queryForRowSet(query,(Object[]) paramArgs);


However, this is giving error when the query has a Date(?) function.



com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-245, SQLSTATE=428F5, SQLERRMC=DATE;1, DRIVER=3.64.96


The description of above error is:



An untyped parameter marker is passed to a function and there are two or more possible candidate functions to resolve to during function resolution.


What is the solution to this?


Thanks for reading!


Aucun commentaire:

Enregistrer un commentaire