Oracle 5.0 Reference Manual page 2122

Table of Contents

Advertisement

important not to lose state information. For this reason, Connector/J will only try to pick a new server
when one of the following happens:
1. At transaction boundaries (transactions are explicitly committed or rolled back).
2. A communication exception (SQL State starting with "08") is encountered.
3. When a
SQLException
the loadBalanceSQLStateFailover,
loadBalanceExceptionChecker
The third condition revolves around three new properties introduced with Connector/J 5.1.13. It allows
you to control which SQLExceptions trigger failover.
loadBalanceExceptionChecker
is really the key. This takes a fully-qualified class name which implements the new
com.mysql.jdbc.LoadBalanceExceptionChecker
you only need to implement the following method:
public boolean shouldExceptionTriggerFailover(SQLException ex)
A
is passed in, and a boolean returned. A value of
SQLException
does not.
You can use this to implement your own custom logic. An example where this might be useful is
when dealing with transient errors when using MySQL Cluster, where certain buffers may become
overloaded. The following code snippet illustrates this:
public class NdbLoadBalanceExceptionChecker
extends StandardLoadBalanceExceptionChecker {
public boolean shouldExceptionTriggerFailover(SQLException ex) {
return super.shouldExceptionTriggerFailover(ex)
||
checkNdbException(ex);
}
private boolean checkNdbException(SQLException ex){
// Have to parse the message since most NDB errors
// are mapped to the same DEMC.
return (ex.getMessage().startsWith("Lock wait timeout exceeded") ||
(ex.getMessage().startsWith("Got temporary error")
&& ex.getMessage().endsWith("from NDB")));
}
}
The code above extends com.mysql.jdbc.StandardLoadBalanceExceptionChecker,
which is the default implementation. There are a few convenient shortcuts built into this, for those
who want to have some level of control using properties, without writing Java code. This default
implementation uses the two remaining properties:
loadBalanceSQLExceptionSubclassFailover.
loadBalanceSQLStateFailover
code prefixes, against which a
triggered. So, for example, the following would trigger a failover if a given
"00", or is "12345":
loadBalanceSQLStateFailover=00,12345
loadBalanceSQLExceptionSubclassFailover
loadBalanceSQLStateFailover
to trigger failover, simply provide a comma-delimited list of fully-qualified class or interface names
to check against. For example, if you want all
failover, you would specify:
Failover with Connector/J
matches conditions defined by user, using the extension points defined by
loadBalanceSQLExceptionSubclassFailover
properties.
- The
loadBalanceExceptionChecker
- allows you to define a comma-delimited list of
is compared. If the prefix matches, failover is
SQLException
or on its own. If you want certain subclasses of
SQLTransientConnectionExceptions
2102
interface. This interface is very simple, and
true
loadBalanceSQLStateFailover
- can be used in conjunction with
property
triggers a failover,
false
and
SQLState
starts with
SQLException
SQLException
to trigger
or

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents