Description Document: http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-replication-connection.html
code example:
1 Importjava.sql.Connection;2 ImportJava.sql.ResultSet;3 Importjava.util.Properties;4 5 ImportCom.mysql.jdbc.ReplicationDriver;6 7 Public classReplicationdriverdemo {8 9 Public Static voidMain (string[] args)throwsException {TenReplicationdriver Driver =Newreplicationdriver (); One AProperties props =NewProperties (); - - //We want this for failover on the slaves theProps.put ("AutoReConnect", "true"); - - //We want to load balance between the slaves -Props.put ("Roundrobinloadbalance", "true"); + -Props.put ("User", "foo"); +Props.put ("Password", "Bar"); A at // - //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 would load balance against - // in -Connection conn = toDriver.connect ("Jdbc:mysql:replication://master,slave1,slave2,slave3/test", + props); - the // * //Perform read/write work on the master $ //By Setting the READ-ONLY flag to "false"Panax Notoginseng // - theConn.setreadonly (false); +Conn.setautocommit (false); AConn.createstatement (). Executeupdate ("UPDATE some_table ....")); the conn.commit (); + - // $ //Now , does a query from a slave, the driver automatically picks one $ //From the list - // - theConn.setreadonly (true); - WuyiResultSet rs = theConn.createstatement (). ExecuteQuery ("Select, b from Alt_table"); - Wu ....... - } About}
From: http://www.cnblogs.com/taven/archive/2013/04/24/3040489.html