private static String format(int num, boolean lengthEquals, int length, int mode) {
        String numStr;
        if (mode == HEX_MODE) {
            numStr = Integer.toHexString(num);
            /* sub hex head '0x' */
            length = length - 2;
        } else if (mode == EIGHT_MODE) {
            numStr = Integer.toOctalString(num);
            /* sub oct head 'o' */
            length = length - 1;
        } else {
            numStr = String.valueOf(num);
        }

        /* append string length for lengthEquals = true */
        if (lengthEquals) {
            if (numStr.length() < length) {
                StringBuilder numberFormatStr = new StringBuilder();
                for (int i = 0; i < length - numStr.length(); i++) {
                    numberFormatStr.append(0);
                }
                numberFormatStr.append(numStr);
                numStr = numberFormatStr.toString();
            }
        }
        return numStr;
    }
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