Affects: 5.1.9


For some reason the Map objects returned by JdbcTemplate.queryForList() use java.lang.Integer to represent database fields defined as SMALLINT. The appropriate mapping would be java.lang.Short. It creates extra code to accept an Integer and then convert to Short. So at best this is a usability issue, but it feels more like a bug.

Database is Db2 11.1.4.4.

Comment From: sbrannen

Hi @jrickard27,

Congratulations on creating your first GitHub issue ever!


JdbcTemplate delegates to ColumnMapRowMapper which delegates to JdbcUtils.getResultSetValue() which invokes java.sql.ResultSet.getObject(int). The Javadoc for the latter states the following.

This method will return the value of the given column as a Java object. The type of the Java object will be the default Java object type corresponding to the column's SQL type, following the mapping for built-in types specified in the JDBC specification.

TABLE B-3 "Mapping from JDBC Types to Java Object Types" in the JDBC 4.1 specification maps TINYINT, SMALLINT, and INTEGER to java.lang.Integer.

The behavior you have described is therefore consistent with the JDBC spec.

It turns out that the H2 database does indeed map SMALLINT to java.lang.Short; whereas, the HSQL database maps SMALLINT to java.lang.Integer, in line with the spec. So if DB2 also maps SMALLINT to java.lang.Integer, that is in line with the spec.

In the end, it depends on the database driver implementation in use.

In light of that, I am closing this issue.

Comment From: jrickard27

Hello, thank you very much for your reply and the explanation. From that, I found the Table B-3 that you referenced and see that it not only confirms what you said but also comes with an explanation of why it is so; historic reasons and backwards compatibility.