- 论坛徽章:
- 6
|
按照mysql的ref设置了一下
用jdbc:mysql://master,slave/testdb 连接
发现只要master或者slave fail掉了,都无法update了(可以select)可用性反而降低了? 
测试代码
- package test;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.util.Properties;
- public class SerivceTest {
- public static void main(String[] args) throws Exception {
- com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver();
- // ReplicationDriver driver = new ReplicationDriver();
- Properties props = new Properties();
- // // We want this for failover on the slaves
- // props.put("autoReconnect", "true");
- //
- // // We want to load balance between the slaves
- // props.put("roundRobinLoadBalance", "true");
- props.put("user", "crud");
- props.put("password", "");
- //
- // 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
- //
- Connection conn =
- driver.connect("jdbc:mysql://master,slave/testdb",
- props);
- //
- // Perform read/write work on the master
- // by setting the read-only flag to "false"
- //
- conn.setReadOnly(false);
- conn.setAutoCommit(false);
- //conn.createStatement().executeUpdate("UPDATE some_table ....");
- conn.commit();
- //
- // Now, do a query from a slave, the driver automatically picks one
- // from the list
- //
- // conn.setReadOnly(true);
- ResultSet rs =
- conn.createStatement().executeQuery("SELECT * FROM test ");
- while(rs.next()) {
- System.out.println(rs.getString("id"));
- }
- }
- }
复制代码 conn.commit();
以后没反应了.
一直在等待,貌似在等待连接已经fail的那个mysql |
|