8.9.2 Loading the Driver and Requesting a Fabric Connection

When using Connector/J with MySQL Fabric, you must provide the host name and port of the MySQL Fabric server instead of the database server. The connection string must follow the same form it normally does, with the addition of the fabric keyword, as follows:

jdbc:mysql:fabric://fabrichost:32274/database

The user name and password provided to the connection are used for authentication with the individual database servers. Fabric authentication parameters can be given in the URL using the fabricUsername and fabricPassword properties. e.g.

jdbc:mysql:fabric://fabrichost:32274/database?fabricUsername=admin&fabricPassword=secret
Note

If the username and password to authenticate to the Fabric node are omitted, no authentication is used. This should only be done when authentication has been disabled on the Fabric node.

Note

If you are using Java 5, you must manually load the driver class before attempting to connect.

Class.forName("com.mysql.fabric.jdbc.Driver");

Connection now proceeds normally.

Connection conn = DriverManager.getConnection(
        "jdbc:mysql:fabric://fabrichost:32274/database",
        user,
        password);

To use the Connector/J APIs that support MySQL Fabric, you must cast the Connection object to the public interface that provides the necessary methods. The interfaces are: