Pavel Bortnovskiy <[email protected]> writes: > Hello: > > Can you please tell me whether this behavior expected or is it a bug? > > 1. a table with SMALLINT is created: > > CREATE TABLE Test_Table (pk_VARCHAR_5FDG6 VARCHAR(256) NOT NULL, > SMALLINT_Q6Y06 SMALLINT, PRIMARY KEY(pk_VARCHAR_5FDG6)) > > 2. values are inserted and Java Short datatype is used to set SMALLINT > values > > 3. values in the table are read with a PreparedStatement "select * > from Test_Table" and then read with: > > while (resultSet.next()) { > final Object object = resultSet.getObject(columnIdx); > } > > 4. at which point, resultSet.getMetaData().getColumnType(columnIdx) == > SMALLINT, but object.getClass() is java.lang.Integer, whereas I would > be expecting java.lang.Short.
Hi Pavel, java.lang.Integer is the correct type for SMALLINT. See table B-3 (Mapping from JDBC Types to Java Object Types) in the JDBC 4.0 specification. There's a note in the specification saying that this mapping is for compatibility with JDBC 1.0, which was finalized before java.lang.Byte and java.lang.Short were added to the Java language. -- Knut Anders
