[CONJ-221] Long cannot be cast to BigInteger Created: 2015-11-19  Updated: 2015-11-24  Resolved: 2015-11-19

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.3.1
Fix Version/s: 1.3.2

Type: Bug Priority: Critical
Reporter: sfahren Assignee: Diego Dupin
Resolution: Fixed Votes: 1
Labels: BigInteger, ClassCastException, Long,
Environment:

MariaDB Server 10.0 and 10.1 installation


Attachments: Zip Archive CastExceptionLongBigInt.zip    

 Description   

On updating the mariaDB Connector from 1.1.8 to 1.3.1 a class cast exception is throwing on insert a long value to a BIGINTEGER column in the database.

In version 1.1.8 it was posstible to create a prepared Statement with the method "setObject(1, valueLong, Types.BIGINT)". Now it throws at this point the exception.

An executable example (from eclipse IDE) is in the attachment including the two connector jars.



 Comments   
Comment by Diego Dupin [ 2015-11-19 ]

Corrected in futur correction release 1.3.2

Additionnal test case added :

 
    @Test
    public void setObjectBitInt() throws SQLException, IOException {
 
        PreparedStatement preparedStatement = sharedConnection.prepareStatement("INSERT INTO TestBigIntType "
                + "(t1, t2, t3, t4) VALUES (?, ?, ?, ?)");
 
        final long valueLong = System.currentTimeMillis();
        final String maxValue = String.valueOf(Long.MAX_VALUE);
 
        preparedStatement.setObject(1, valueLong, Types.BIGINT);
        preparedStatement.setObject(2, maxValue, Types.BIGINT);
        preparedStatement.setObject(3, valueLong);
        preparedStatement.setObject(4, maxValue);
        preparedStatement.executeUpdate();
 
        Statement statement = sharedConnection.createStatement();
        ResultSet rs = statement.executeQuery("SELECT * FROM TestBigIntType");
        validateResultBigIntType(valueLong, maxValue, rs);
 
 
        PreparedStatement ps = sharedConnection.prepareStatement("SELECT * FROM TestBigIntType Where 1 = ?");
        ps.setInt(1, 1);
        rs =  ps.executeQuery();
        validateResultBigIntType(valueLong, maxValue, rs);
 
    }
 
    private void validateResultBigIntType(long valueLong, String maxValue, ResultSet resultSet) throws SQLException {
        if (resultSet.next()) {
            assertEquals(resultSet.getLong(1), valueLong);
            assertEquals(resultSet.getLong(2), Long.parseLong(maxValue));
            assertEquals(resultSet.getLong(3), valueLong);
            assertEquals(resultSet.getLong(4), Long.parseLong(maxValue));
        } else {
            fail();
        }
    }

Generated at Thu Feb 08 03:14:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.