Bug #12931 getObject on int(10) primary key seems to be returing invalid value
Submitted: 1 Sep 2005 16:15 Modified: 1 Sep 2005 16:21
Reporter: Sam Dribin Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.10 OS:Windows (WinXP)
Assigned to: CPU Architecture:Any

[1 Sep 2005 16:15] Sam Dribin
Description:
getObject and getLong() on unsigned int(10) columns seem to have an invalid bit set, resulting in incorrect values.

How to repeat:
Running on MySql server  4.1.12a-nt, windows XP.

A) Create the following sql:

create table test (id int unsigned NOT NULL auto_increment, primary key(id));
insert into test (1),(2),(3);

B) Run the following Java code:

        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager
                .getConnection("jdbc:mysql://localhost/testdb")

        final PreparedStatement ps = conn.prepareStatement("select * from test");

        final ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getObject(1));
            System.out.println(rs.getObject(1).getClass().getName());
            System.out.println(rs.getObject(1).toString());
            System.out.println(rs.getLong(1));
            System.out.println(rs.getInt(1));
            System.out.println(rs.getString(1));
            System.out.println(rs.getBigDecimal(1));
            System.out.println("--------");
        }

C) The output is as follows:

4294967297
java.lang.Long
4294967297
4294967297
1
1
1
--------
4294967298
java.lang.Long
4294967298
4294967298
2
2
2
--------
4294967299
java.lang.Long
4294967299
4294967299
3
3
3
--------

D) The output for the following table (correct) is:

1
java.lang.Integer
1
1
1
1
1
--------
2
java.lang.Integer
2
2
2
2
2
--------
3
java.lang.Integer
3
3
3
3
3
--------
[1 Sep 2005 16:16] Sam Dribin
Sorry, forgot the second table:

create table test (id int NOT NULL auto_increment, primary key(id));

This works correctly.
[1 Sep 2005 16:21] Mark Matthews
Known issue, fixed in 3.1.11, nightly snapshots are available until release of 3.1.11 at 
http://downloads.mysql.com/snapshots.php#connector-j

(from the changelog for 3.1.11)

 Fixed regression caused by fix for BUG#11552 that caused driver
      to return incorrect values for unsigned integers when those 
      integers where within the range of the positive signed type.