I am new to Spring and trying to write a simple test method that uses NamedParameterJdbcTemplate. Here it is:
public String test() {
String query = "SELECT CURRENT DATE FROM :table ;";
return String.valueOf(this.namedTemplate.queryForObject(query,
new MapSqlParameterSource("table", "sysibm.sysdummy1"),
String.class));
}
In DB2, that query should return today's date. However, I get an exception:
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT CURRENT DATE FROM ? ;]; nested exception is com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=?;( XMLTABLE TABLE FINAL OLD, DRIVER=4.13.127
SQLCODE -104 is "illegal symbol." I guess this is referring to the ?
. Why is it getting that instead of the "sysibm.sysdummy1"
string?