DB2 query runs in IBM Data Studio but not in code

2019-09-11 00:20发布

问题:

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
标签: java sql db2