Bug #103303 java.lang.ClassCastException when inserting blob with server prepared statement
Submitted: 13 Apr 12:53 Modified: 14 Apr 5:15
Reporter: Andrey Tarashevskiy Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.23 OS:Any
Assigned to: CPU Architecture:Any

[13 Apr 12:53] Andrey Tarashevskiy
Description:
It's impossible to set blobs when used connected with `useServerPrepStmts=true&rewriteBatchedStatements=true` parameters as it fails with ClassCastException:
```
java.lang.ClassCastException: com.mysql.cj.jdbc.Blob cannot be cast to java.io.Reader
at com.mysql.cj.jdbc.ServerPreparedStatement.setOneBatchedParameterSet(ServerPreparedStatement.java:729)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchedInserts(ClientPreparedStatement.java:712)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeBatchInternal(ClientPreparedStatement.java:426)
at com.mysql.cj.jdbc.StatementImpl.executeBatch(StatementImpl.java:794)
```

How to repeat:
1. Connect to mysql with `useServerPrepStmts=true&rewriteBatchedStatements=true` in connection url

2. Create simple table with: 
``` CREATE TABLE t1 (
  id INT AUTO_INCREMENT PRIMARY KEY,
  blob1 MEDIUMBLOB
)
```

3. Execute provided code
```
public class BlobTest {

    public void testBlob(Connection connection) throws SQLException {
        PreparedStatement statement = connection.prepareStatement("INSERT INTO t1(blob1) VALUES(?);", PreparedStatement.RETURN_GENERATED_KEYS);
        Blob blob = new SerialBlob("test".getBytes());
        statement.setBlob(1, blob);
        statement.addBatch();
        statement.setBlob(1, blob);
        statement.executeBatch();
    }
}
```
[14 Apr 5:15] Alexander Soklakov
Hi Andrey,

Thanks for the report!