public static Connection getConnectionFailover(String driverClassName,
            String connectionUrl,
            String userName,
            String password) throws Exception {

        int totalRetryTimes = 3;
        int timeInterval = 10;

        connectionUrl = StringUtils.trim(connectionUrl);
        connectionUrl = StringUtils.replace(connectionUrl, "\r", "");
        connectionUrl = StringUtils.replace(connectionUrl, "\n", "");

        /* TODO: try to decrypt password, if failed then use raw password */

        /*
         * NOTE: THIS MAY CAUSE DEADLOAK WHEN MULTIPLE THREADS CALLED AT THE SAME TIME
         * sun.security.jca.ProviderConfig.getProvider(ProviderConfig.java:188)
         */
        synchronized (AgentDbUtils.class) {
            DbUtils.loadDriver(driverClassName);
        }

        Connection conn = null;
        int retryTimes = 0;
        while (conn == null) {
            try {
                conn = DriverManager.getConnection(connectionUrl, userName, password);
            } catch (Exception e) {
                retryTimes++;
                if (retryTimes >= totalRetryTimes) {
                    throw new SQLException(
                            "Failed to connect database after retry " + retryTimes + " times.", e);
                }
                TimeUnit.SECONDS.sleep(timeInterval);
            }
        }

        conn.setAutoCommit(false);
        return conn;
    }
Attempts to establish a connection to the database from the XML configurations. If failed,
try use alternative standby database.

@return Database connection
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentDbUtils.java