Bug #12010 ResultSet.getObject behaves strange on UNSIGNED int's with Prepared statements.
Submitted: 18 Jul 2005 16:05 Modified: 18 Jul 2005 16:14
Reporter: Robbert-Jan Roos Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.10-stable OS:Linux (linux and windows)
Assigned to: CPU Architecture:Any

[18 Jul 2005 16:05] Robbert-Jan Roos
Description:
When using a server side PreparedStatement with jconnect 3.1.10-stable and mysql 4.1 the method ResultSet.getObject will always return 2^32 when used on an unsigned int.
When Using the useServerPrepStmts flag to turn the feature off it works perfectly. 

How to repeat:
CREATE TABLE test (systemid INT UNSIGNED PRIMARY KEY AUTO_INCREMENT;
INSERT INTO test() VALUES ();

test.java:
-------------------------------------
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class test {

	public static void main(String[] args) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
   
	    Properties props = new Properties();
	    props.put("user", "user");
	    props.put("password", "pass");
	    
	    Connection c1 = DriverManager.getConnection(
				"jdbc:mysql://server/test", props);
	    go(c1);
	    c1.close();
	    
	    props.put("useServerPrepStmts", "false");
	    c1 = DriverManager.getConnection(
				"jdbc:mysql://server/test", props);
	    go(c1);
	    c1.close();
	}
	
	private static void go(Connection c) throws Exception {
		DatabaseMetaData dm = c.getMetaData();
		System.out.println(dm.getDriverVersion());
		
		PreparedStatement s = c.prepareStatement(
				"SELECT systemid FROM test ",
				ResultSet.TYPE_FORWARD_ONLY,
				ResultSet.CONCUR_READ_ONLY);
		ResultSet rs = s.executeQuery();
		
		while (rs.next()) {
			System.out.println(rs.getInt("systemid"));
			Object o = rs.getObject("systemid");
			System.out.println(o);
			System.out.println(o.getClass());
		}
	}	
}
-------------------------------------

Outputs:
mysql-connector-java-3.1.10 ( $Date: 2005/05/19 15:52:23 $, $Revision: 1.1.2.2 $ )
1
4294967297
class java.lang.Long
mysql-connector-java-3.1.10 ( $Date: 2005/05/19 15:52:23 $, $Revision: 1.1.2.2 $ )
1
1
class java.lang.Long
[18 Jul 2005 16:14] Mark Matthews
Duplicate bug, already fixed for 3.1.11, see nightly builds at http://downloads.mysql.com/snapshots.php#connector-j