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