Bug #12032 Contradictory behavior of getInt() & getShort() inPreparedStatment & Statement
Submitted: 19 Jul 2005 14:12 Modified: 19 Jul 2005 14:30
Reporter: David Morton Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.10 OS:Linux (Fedora Core 3)
Assigned to: CPU Architecture:Any

[19 Jul 2005 14:12] David Morton
Description:
We are seeing different results from getInt() and getShort() in PreparedStatements and Statements operating on the same data.

How to repeat:

1) We created the following table:
CREATE TABLE `bugTest1` (
  `id` varchar(12) NOT NULL default '',
  `testVar` tinyint(3) unsigned NOT NULL default '0'
);
 
INSERT INTO `bugTest1` VALUES (' A', 3);
INSERT INTO `bugTest1` VALUES ('B', 205);

CREATED THIS TEST CLASS:

import java.sql.*;
 
public class BUG1{
 
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test?user=test&password=test");
 
        System.out.println("** QUERY USING Statements **");
        Statement st=conn.createStatement();
        ResultSet rset=st.executeQuery("SELECT testVar from bugTest1");
        while(rset.next()){
            int statementInt=rset.getInt(1);
            short statementShort=rset.getShort(1);
            System.out.println("statementInt:"+statementInt);
            System.out.println("statementShort:"+statementShort);
             
        }
        rset.close();
        st.close();
 
        System.out.println("** QUERY USING PreparedStatements **");
        PreparedStatement ps=conn.prepareStatement("SELECT testVar from bugTest1");
        rset=ps.executeQuery();
 
        while(rset.next()){
            int preparedStatementInt=rset.getInt(1);
            short preparedStatementShort=rset.getShort(1);
            System.out.println("preparedStatementInt:"+preparedStatementInt);
            System.out.println("preparedStatementShort:"+preparedStatementShort);
             
        }
        rset.close();
        ps.close();
 
        conn.close();
 
        System.exit(0);
    }
 
}

3) THIS PRODUCED THE FOLLOWING RESULT IN THE 3.1.8 
[root@dev bug1]# java -classpath 'mysql-connector-java-3.1.8-bin.jar:.' BUG1
** QUERY USING Statements **
statementInt:3
statementShort:3
statementInt:205
statementShort:205
** QUERY USING PreparedStatements **
preparedStatementInt:3
preparedStatementShort:3
preparedStatementInt:-51
preparedStatementShort:-51
 
3) THIS PRODUCED THE FOLLOWING RESULT IN THE 3.1.10
[root@dev bug1]# java -classpath 'mysql-connector-java-3.1.10-bin.jar:.' BUG1
** QUERY USING Statements **
statementInt:3
statementShort:3
statementInt:205
statementShort:205
** QUERY USING PreparedStatements **
preparedStatementInt:259
preparedStatementShort:3
preparedStatementInt:205
preparedStatementShort:-51
[19 Jul 2005 14:30] Mark Matthews
Dupe of a few bugs related to unsigned behavior with prepared statements. See the latest nightly snapshot(s) of 3.1, where this has already been fixed for 3.1.11.

(http://downloads.mysql.com/snapshots.php#connector-j)