类 ConnectionUrlParser

  • 所有已实现的接口:
    DatabaseUrlContainer

    public class ConnectionUrlParser
    extends Object
    implements DatabaseUrlContainer
    This class parses a connection string using the general URI structure defined in RFC 3986. Instead of using a URI instance to ensure the correct syntax of the connection string, this implementation uses regular expressions which is faster but also less strict in terms of validations. This actually works better because database URLs don't exactly stick to the RFC 3986 rules.

    scheme://authority/path?query#fragment

    This results in splitting the connection string URL and processing its internal parts:

    scheme
    The protocol and subprotocol identification. Usually "jdbc:mysql:" or "mysqlx:".
    authority
    Contains information about the user credentials and/or the host and port information. Unlike its definition in the RFC 3986 specification, there can be multiple authority sections separated by a single comma (,) in a connection string. It is also possible to use an alternative syntax for the user and/or host identification, that also allows setting per host connection properties, in the form of "[user[:password]@]address=(key1=value)[(key2=value)]...[,address=(key3=value)[(key4=value)]...]...".
    path
    Corresponds to the database identification.
    query
    The connection properties, written as "propertyName1[=[propertyValue1]][&propertyName2[=[propertyValue2]]]..."
    fragment
    The fragment section is ignored in Connector/J connection strings.
    • 方法详细资料

      • parseConnectionString

        public static ConnectionUrlParser parseConnectionString​(String connString)
        Static factory method for constructing instances of this class.
        参数:
        connString - The connection string to parse.
        返回:
        an instance of ConnectionUrlParser
      • isConnectionStringSupported

        public static boolean isConnectionStringSupported​(String connString)
        Checks if the scheme part of given connection string matches one of the ConnectionUrl.Types supported by Connector/J. Throws WrongArgumentException if connString is null.
        参数:
        connString - connection string
        返回:
        true if supported
      • parseUserInfo

        public static ConnectionUrlParser.Pair<String,​String> parseUserInfo​(String userInfo)
        Parses the given user information which is formed by the parts [user][:password].
        参数:
        userInfo - the string containing the user information
        返回:
        a ConnectionUrlParser.Pair containing the user and password information or null if the user information can't be parsed
      • getDatabaseUrl

        public String getDatabaseUrl()
        Returns the original database URL that produced this connection string parser.
        指定者:
        getDatabaseUrl 在接口中 DatabaseUrlContainer
        返回:
        the original database URL
      • getScheme

        public String getScheme()
        Returns the scheme section.
        返回:
        the scheme section
      • getAuthority

        public String getAuthority()
        Returns the authority section.
        返回:
        the authority section
      • getPath

        public String getPath()
        Returns the path section.
        返回:
        the path section
      • getQuery

        public String getQuery()
        Returns the query section.
        返回:
        the query section
      • getHosts

        public List<HostInfo> getHosts()
        Returns the hosts information.
        返回:
        the hosts information
      • getProperties

        public Map<String,​String> getProperties()
        Returns the properties map contained in this connection string.
        返回:
        the properties map
      • toString

        public String toString()
        Returns a string representation of this object.
        覆盖:
        toString 在类中 Object
        返回:
        a string representation of this object