0

I am attempting to get the ResultsetMetadata from a spring jdbc query. When I run the code I get a bad SQL grammar error (below). Running the same query in IBM Data Studio returns a result. Part of my confusion is that the error is Parameter index is out of range despite the fact that my query isn't parameterised.

List rsmdList = sourceJdbcTemplate.queryForList("SELECT * FROM MYSCHEMA.MYTABLE fetch first 1 rows only", new ResultSetExtractor() {
            @Override
            public ResultSetMetaData extractData(ResultSet rs) throws SQLException, DataAccessException {
                ResultSetMetaData rsmd = rs.getMetaData();
                return rsmd;
            }
        });

Exception:

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT * FROM MYSCHEMA.MYTABLE fetch first 1 rows only]; nested exception is com.ibm.db2.jcc.am.vo: [jcc][10145][10844][4.8.87] Invalid parameter 1: Parameter index is out of range. ERRORCODE=-4461, SQLSTATE=42815
Romski
  • 1,912
  • 1
  • 12
  • 27
  • Ckeck out the similar case of yours http://stackoverflow.com/questions/13190249/jdbctemplate-does-not-support-parameterized-query-in-case-must-by-namedparame – knkarthick24 Oct 27 '14 at 07:44
  • My apologies if I've missed something, but my query isn't parameterised which is partly why Im surprised by the error - I'll update the question – Romski Oct 27 '14 at 07:56

0 Answers0