/**
 * Testcase for http://bugs.mysql.com/11879
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.Properties;

// import com.mysql.jdbc.ReplicationDriver;

public class ReplicationDriverTest {

    static final String driver = "com.mysql.jdbc.ReplicationDriver";
    static final String url = "jdbc:mysql://localhost:3307,localhost:3308/gobi";

    public static void main(String[] args) throws Exception {
            
        Properties props = new Properties();

        props.setProperty("user", "foo");
        props.setProperty("password", "foo");
        props.setProperty("autoReconnect", "true");
        props.setProperty("roundRobinLoadBalance", "true");

        Class.forName(driver);
        Connection con = DriverManager.getConnection(url, props);

        // directly creating the driver throws the same exception
        // ReplicationDriver driver = new ReplicationDriver();
        // Connection con = driver.connect(url, props);

        // these lines don't seem to make any difference
        // con.setReadOnly(false);
        // con.setAutoCommit(false);
        // con.createStatement().executeUpdate("UPDATE page set title = 'foo' where id = 1234567");
        // con.commit();

        con.setReadOnly(true);
        ResultSet rs = con.createStatement()
                .executeQuery("SELECT * from page");

        while (rs.next()) {}

        con.close();
    }
}
