import java.sql.*; import java.util.*; public class Bug8643 { public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306,localhost:3307/test"; Properties props = new Properties(); props.put("autoReconnect", "true"); props.put("roundRobinLoadBalance", "true"); props.put("failOverReadOnly", "false"); props.put("user", "root"); props.put("password", ""); Connection con = DriverManager.getConnection(url, props); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("show variables like 'port'"); rs.next(); System.out.println("connected to port:" + rs.getString(2)); rs = stmt.executeQuery("select connection_id()"); rs.next(); String originalConnectionId = rs.getString(1); stmt.executeUpdate("kill " + originalConnectionId); try { rs = stmt.executeQuery("show variables like 'port'"); } catch (SQLException ex) { // failover and retry rs = stmt.executeQuery("show variables like 'port'"); } rs.next(); System.out.println("connected to port:" + rs.getString(2)); rs = stmt.executeQuery("select connection_id()"); rs.next(); originalConnectionId = rs.getString(1); stmt.executeUpdate("kill " + originalConnectionId); try { rs = stmt.executeQuery("show variables like 'port'"); } catch (SQLException ex) { // failover and retry rs = stmt.executeQuery("show variables like 'port'"); } rs.next(); System.out.println("connected to port:" + rs.getString(2)); con.close(); } }