class JDBC {

    public static String tryExtractServerString(String url) {
        /*
            jdbc:microsoft:sqlserver://<server_name>:<port> -> port is optional
            jdbc:sqlserver://<server_name>:<port>
            jdbc:oracle:thin:@//<host>:<port>/ServiceName
            jdbc:oracle:thin:@<host>:<port>:<SID>
            jdbc:db2://<host>[:<port>]/<database_name>
            jdbc:mysql://<host>:<port>/<database_name>
            jdbc:postgresql://<host>:<port>/<database_name>
            jdbc:h2:tcp://<server>[:<port>]/[<path>]<databaseName>
            jdbc:h2:[file:][<path>]<databaseName>
            jdbc:h2:<url>[;USER=<username>][;PASSWORD=<value>]

         */
        if(!Strings.startsWith(url, "jdbc:", true)) {
            return null;
        }

        url = Urls.removeQueryString(url);

        //removes jdbc:dbtype:
        int index = url.indexOf(':',5);
        if(index < 0) {
            //unknown url
            return null;
        }else{
            url = url.substring(index+1);
        }

        //remove parameters like jdbc url : jdbc:h2:<url>[;USER=<username>][;PASSWORD=<value>]
        index = url.indexOf(';');
        if(index > 0) {
            url = url.substring(0, index);
        }

        index = url.indexOf("//");
        if(index >= 0) {
            url = url.substring(index + 2);
        }else {
            index = url.indexOf('@');
            if(index >= 0) {
                url = url.substring(index + 1);
            }
        }

        index = url.indexOf('/');
        if(index > 0) {
            url = url.substring(0, index);
        }

        String[] parts = Strings.split(url, ':');
        if(parts.length >= 2) {
            return parts[0] + ":" + parts[1];
        }else{
            //hostname or ip address only
            if(url.length() <= 5){
                return null;
            }
            return url;
        }
    }

    protected  JDBC();

}