Bug #13464 ResultSet.getInt() returns value+65536 for SMALLINT UNSIGNED
Submitted: 25 Sep 2005 5:44 Modified: 25 Sep 2005 9:56
Reporter: Edward Yang Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1.10 OS:Java/WinXP
Assigned to: CPU Architecture:Any

[25 Sep 2005 5:44] Edward Yang
Description:
If the SQL type of column i is SMALLINT UNSIGNED and a value less than 32768 is stored on the column, calling ResultSet.getInt(i) returns a value which is 65536 plus the actual value.
This also causes ResultSet.getObject(i) to return a Integer which is 65536 greater than the actual value of the column when a value less than 32768 is stored on the column.
Specifically, in source code of class com.mysql.jdbc.ResultSet line 3664, the value obtained from getNativeShort() is unconditionally added with 65536, whether it is negative (which should be added with 65536) or positive (which should not).

How to repeat:
1. Create a table with a SMALLINT UNSIGNED column.
2. Insert a row with positive value on that column to that table.
3. In Java, select that row to a ResultSet rs and call rs.getInt(i), where i is the column index.
4. The integer obtained is 65536 greater than the actual value.

Suggested fix:
Put a sign check before the "getNativeShort(columnIndex + 1) + 65536" on line 3664 of com/mysql/jdbc/ResultSet.java. Return the native short plus 65536 only if the value is negative.
[25 Sep 2005 9:56] Vasily Kishkin
Sorry...This bug is duplicate of http://bugs.mysql.com/bug.php?id=11874