Bug #13474 getInt() returns value + 256 for UNSIGNED TINYINT
Submitted: 26 Sep 2005 7:11 Modified: 26 Sep 2005 8:40
Reporter: Stefan Kausl Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.1.10 OS:Windows (Windows)
Assigned to: CPU Architecture:Any

[26 Sep 2005 7:11] Stefan Kausl
Description:
For UNSIGNED TINYINT com.mysql.jdbc.ResultSet.getInt(int) calls getNativeInt(int) which returns getNativeByte(columnIndex + 1) + 256 (see line 3658). Therefore code like int id = rs.getInt(1); for UNSIGNED TINYINT is broken. You must use int id = rs.getByte(1). The same applies to SHORT. I think this is a common source of trouble and should be fixed.

How to repeat:
int id = rs.getInt(1);

Suggested fix:
In method com.mysql.jdbc.ResultSet.getNativeInt(int)

  return getNativeByte(columnIndex + 1) & 0xff;

instead of

  return getNativeByte(columnIndex + 1) + 256;

and

  return getNativeShort(columnIndex + 1) & 0xffff;

instead of

  return getNativeShort(columnIndex + 1) + 65536;
[26 Sep 2005 8:40] Vasily Kishkin
Thanks for the bug report. But the bug is duplicate of http://bugs.mysql.com/bug.php?id=11874
[26 Sep 2005 12:46] Mark Matthews
Duplicate of http://bugs.mysql.com/bug.php?id=11874 

The fix has been in the nightly build of 3.1 for some time (3.1.11 is to be released soon), see http://downloads.mysql.com/snapshots.php#connector-j