Reputation: 83
I found the code in ResultSetMetaData:
case Types.SMALLINT:
if (isUnsigned) {
return "java.lang.Integer";
}
return "java.lang.Integer";
But in many document , smallint should be mapped to short.
Upvotes: 1
Views: 620
Reputation: 5516
In the JDBC 1.0 specification the mapping from SMALLINT and TINYINT was defined to an integer. For backwards compatibility they use also in the new version these conversion.
See JDBC spec page 187:
Note – The JDBC 1.0 specification defined the Java object mapping for the SMALLINT and TINYINT JDBC types to be Integer. The Java language did not include the Byte and Short data types when the JDBC 1.0 specification was finalized. The mapping of SMALLINT and TINYINT to Integer is maintained to preserve backwards compatibility
The MySQL jdbc developers followed the jdbc spec and implemented the conversation from SMALLINT to an Integer.
Also you can see in the mysql doucmentation the conversion from smallint to int.
The ResultSet.getObject() method uses the type conversions between MySQL and Java types, following the JDBC specification where appropriate.
See the table:
Table 5.2 MySQL Types to Java Types for ResultSet.getObject()
MySQL Type Name Return value of GetColumnClassNameReturned as Java Class
SMALLINT[(M)] [UNSIGNED] SMALLINT [UNSIGNED] java.lang.Integer (regardless if UNSIGNED or not)
Upvotes: 1