Open source reader

Tuesday, May 09, 2006

A simple Mysql replication mechanism within the jdbc driver

Found here a solution within the mysql jdbc driver to do round robin ...
Basically here what is provided using the com.mysql.jdbc.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", "foo");
props.put("password", "bar");

Connection conn = driver.connect("jdbc:mysql://master,slave1,slave2,slave3/test", props);
A little something from you in order to use this method, declare when you are reading via:
 conn.setReadOnly(true);
or writing via :
        conn.setReadOnly(false);
conn.setAutoCommit(false);

Simple enough...

0 Comments:

Post a Comment

<< Home