Communication link failure: JDBC

28 views Asked by At

I have a MySqlConnection class for a distributed database in 3 cities. I want to access to 3 different IPs, but when the program tries to connect to a node, JDBC shows an exception of "Communications link failure".

The code is the next one:

public class MySqlConnection { 
    private String DB_URL;
    private String USER;
    private String PASSWORD;
    private Connection connection;    

    public Connection GetConnection(String node)
    {
        switch (node)
        {
            case "City1":
                DB_URL = "jdbc:mysql://192.168.100.8:3306/DATABASE_NAME";
                USER = "root";
                PASSWORD = "password_node1";
                break;
            case "City2":
                DB_URL = "jdbc:mysql://192.168.100.11:3306/DATABASE_NAME";
                USER = "root";
                PASSWORD = "password_node2";
                break;
            case "City3":
                DB_URL = "jdbc:mysql://192.168.100.13:3306/DATABASE_NAME";
                USER = "root";
                PASSWORD = "password_node3";
                break;
        }
        try
        {
            connection = (Connection) DriverManager.getConnection(DB_URL, USER, PASSWORD);
        }
        catch(SQLException ex)
        {
            JOptionPane.showMessageDialog(null, ex);
        }
        return connection;
    }
}

Note that I've 3 PCs with its mysql server, and all with different IPs. I'm using Ubuntu 17.04 in all PCs. Thank you instead.

0

There are 0 answers