Bug #77217 ClassCastException when executing a PreparedStatement with Fabric
Submitted: 1 Jun 2015 23:42 Modified: 15 Jun 2015 22:59
Reporter: John Krieger Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.35 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[1 Jun 2015 23:42] John Krieger
Description:
Manifests as nested exception, relevant part of stack trace shown below.

Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy17 cannot be cast to com.mysql.jdbc.StatementImpl
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1995)

How to repeat:
This error only manifested in the Fabric environment.

Suggested fix:
Use the same code block in PreparedStatement.executeQuery as found in PrepatedStatement.execute. The attempt to cast the dynamic proxy to StatementImpl is what causes the error. We have recompiled the driver with the fix below and it resolves the issue for us.

            if (doStreaming && this.connection.getNetTimeoutForStreamingResults() > 0) {
                executeSimpleNonQuery(this.connection, "SET net_write_timeout=" + this.connection.getNetTimeoutForStreamingResults());
            }
[2 Jun 2015 11:03] Filipe Silva
Hi John,

Thank you for this bug report.
Verified by code review.
[15 Jun 2015 22:59] Daniel So
Added the following entry to the Connector/J 5.1.36 changelog:

"A class cast exception occurred when Connector/J was executing a streaming prepared statement in a Fabric environment."