Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
2.4.1
-
Ubuntu 18.04 (OS)
10.3.14 (MariaDB)
1.8.0_191/64-Bit (OpenJDK)
mariadb-java-client-2.4.1 (Driver)
Description
Failover and Load Balancing Parameters :: autoReconnect
When this parameter enabled when a Failover and Load Balancing Mode is not in use, the connector will simply try to reconnect to its host after a failure. This is referred to as Basic Failover.
import java.sql.*; |
import java.util.Properties; |
|
public class JDBCExample { |
static final String DB_URL = "jdbc:mariadb://myip:myport/mydb"; |
static final String USER = "myuser"; |
static final String PASS = "mypass"; |
|
public static void main(String[] args) { |
Properties props = new Properties(); |
props.put("user", USER); |
props.put("password", PASS); |
props.put("autoReconnect", "true"); |
|
try (Connection conn = |
DriverManager.getConnection(DB_URL, props)) {
|
Statement stmt = conn.createStatement();
|
ResultSet rs = stmt.executeQuery("SELECT 1;"); |
|
stmt.execute("SET SESSION wait_timeout = 1;"); |
Thread.sleep(3000); // or restart MariaDB Server |
|
try { |
rs = stmt.executeQuery("SELECT 1;"); |
System.out.println("1"); |
} catch (SQLException e) { |
System.out.println("2"); |
} finally { |
rs.close();
|
stmt.close();
|
conn.close();
|
}
|
} catch (SQLException se) { |
se.printStackTrace();
|
} catch (Exception e) { |
e.printStackTrace();
|
}
|
}
|
}
|
According to the documentation, the expected result should be 1 (reconnect), however, it's 2. Why doesn't the driver reconnect?.