}
}
static void initConnection() throws Exception {
String url = "jdbc:mysql://localhost,localhost:3306/test";
ReplicationDriver driver = new ReplicationDriver();
Properties props = new Properties();
//props.put("propertiesTransform", "my.NotFoundConnectionPropertiesTransform");
props.put("user", "root");
props.put("password", "test");
props.put("holdResultsOpenOverStatementClose", "true");
//props.put("allowMultiQueries","true");
props.put("useCursorFetch", "true");
//props.put("traceProtocol","true");
// We want this for failover on the slaves
//props.put("autoReconnect", "true");
// We want to load balance between the slaves
props.put("roundRobinLoadBalance", "true");
//会抛出NullPointerException,是个Bug???
//props.put("retriesAllDown", "0");
props.put("retriesAllDown", "3"); //retriesAllDown默认是120,所以主机不可用时重试次数
props.put("loadBalanceBlacklistTimeout", "1");
//loadBalanceStrategy默认是random,也可以自定义一个实现com.mysql.jdbc.BalanceStrategy接口的类
props.put("loadBalanceStrategy", "bestResponseTime");
//
// Looks like a normal MySQL JDBC url, with a
// comma-separated list of hosts, the first
// being the 'master', the rest being any number
// of slaves that the driver will load balance against
//
conn = driver.connect(url, props);
}