Description:
The JDBC specs define which Java object classes should be returned from ResultSet.getObject for which SQL types. See table B-3 in the JDBC 3.0 specification, which is consistent with previous versions.
Incorrect classes are returned for columns with a SQL type of TINYINT or SMALLINT. They should return an Integer object. TINYINT returns Byte or Short, depending on whether the column is signed. SMALLINT returns Short or Integer, depending on whether the column is signed.
How to repeat:
From within Java:
try {statement.executeUpdate("DROP TABLE BadObjectTypes");} catch (SQLException e){}
statement.executeUpdate("CREATE TABLE BadObjectTypes (f1 TINYINT NOT NULL, f2 SMALLINT NOT NULL)");
statement.executeUpdate("INSERT INTO BadObjectTypes VALUES (0,0)");
ResultSet rs = statement.executeQuery("SELECT * FROM BadObjectTypes");
rs.next();
System.out.println(rs.getObject(1).getClass());
System.out.println(rs.getObject(2).getClass());
rs.close();
I would expect:
class java.lang.Integer
class java.lang.Integer
I get:
class java.lang.Byte
class java.lang.Short
Suggested fix:
The switch statement in ResultSet.getObject(int) should be modified for the appropriate cases:
case Types.TINYINT:
return new Integer(getInt(columnIndex));
case Types.SMALLINT:
return new Integer(getInt(columnIndex));
While this will allow code written to the JDBC specification to work, it has the potential to break code written to existing versions of MySQL Connector/J. It may be worth adding a connection property to perserve the old behavior.
Description: The JDBC specs define which Java object classes should be returned from ResultSet.getObject for which SQL types. See table B-3 in the JDBC 3.0 specification, which is consistent with previous versions. Incorrect classes are returned for columns with a SQL type of TINYINT or SMALLINT. They should return an Integer object. TINYINT returns Byte or Short, depending on whether the column is signed. SMALLINT returns Short or Integer, depending on whether the column is signed. How to repeat: From within Java: try {statement.executeUpdate("DROP TABLE BadObjectTypes");} catch (SQLException e){} statement.executeUpdate("CREATE TABLE BadObjectTypes (f1 TINYINT NOT NULL, f2 SMALLINT NOT NULL)"); statement.executeUpdate("INSERT INTO BadObjectTypes VALUES (0,0)"); ResultSet rs = statement.executeQuery("SELECT * FROM BadObjectTypes"); rs.next(); System.out.println(rs.getObject(1).getClass()); System.out.println(rs.getObject(2).getClass()); rs.close(); I would expect: class java.lang.Integer class java.lang.Integer I get: class java.lang.Byte class java.lang.Short Suggested fix: The switch statement in ResultSet.getObject(int) should be modified for the appropriate cases: case Types.TINYINT: return new Integer(getInt(columnIndex)); case Types.SMALLINT: return new Integer(getInt(columnIndex)); While this will allow code written to the JDBC specification to work, it has the potential to break code written to existing versions of MySQL Connector/J. It may be worth adding a connection property to perserve the old behavior.