Bug #75168 loadBalanceExceptionChecker interface cannot work using JDBC4/JDK7
Submitted: 11 Dec 2014 3:50 Modified: 4 Feb 2015 15:04
Reporter: Aiden Zhang Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.34 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: loadBalanceExceptionChecker, loadBalanceSQLExceptionSubclassFailover, loadBalanceSQLStateFailover

[11 Dec 2014 3:50] Aiden Zhang
Description:
JDK7.x JDBC4 with Mysql JDBC 5.1.34

"jdbc:mysql:loadbalance://10.228.169.99:3306,10.228.169.100:3306/test?user=aicent&password=aicent&allowMasterDownConnections=false&autoReconnectForPools=true&secondsBeforeRetryMaster=10&failOverReadOnly=false&loadBalanceExceptionChecker=com.aicent.wifi.jdbc.ha.MyLoadBalanceExceptionChecker&retriesAllDown=10";

When an exception happends, like the table doest not exist, which cannot invoke my class: MyLoadBalanceExceptionChecker.

How to repeat:
Just with the same configuration.

public class MyLoadBalanceExceptionChecker extends
		StandardLoadBalanceExceptionChecker {

        @Override
	public boolean shouldExceptionTriggerFailover(SQLException ex) {
		System.out.println("MyLoadBalanceExceptionChecker:" + ex.getMessage());
		return true;
	}

}

Suggested fix:
file: LoadBalancingConnectionProxy.java
method: private boolean isInterfaceJdbc(Class<?> clazz) 

line 714:
Class<?>[] interfaces = clazz.getInterfaces();

Since the JDBC4XXX, like JDBC4PreparedStatement, just extends the com.mysql.jdbc.PreparedStatement, cannot get the interface java.sql.PreparedStatement, so the proxy cannot work well for the JDBC4 related classes.
[12 Dec 2014 14:23] Filipe Silva
Hi Aiden,

Thank you for this bug report. Incorrect behavior was verified as described.
[4 Feb 2015 15:04] Daniel So
Added the following entry to the Connector/J 5.1.35 changelog:

"When using JDBC 4 features of Connector/J 5.1 with JDK 6 and above, custom implementations of the interface LoadBalanceExceptionChecker failed to work. This was because most of the JDBC 4-specific classes of Connector/J do not implement a JDBC interface directly, but extend other JDBC 3 classes instead, so that the LoadBalancingConnectionProxy.isInterfaceJdbc() check did not work. This fix makes the checking work by extending its search to include also the super classes."