0
votes

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
Ckeck out the similar case of yours stackoverflow.com/questions/13190249/…knkarthick24
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 questionRomski