code: public static String extractServerUrl(String url)
      {
          int rightIndex = url.length();
          if (url.lastIndexOf("/") != -1) { rightIndex = url.lastIndexOf("/"); }
          else if (url.lastIndexOf(":") != -1) { rightIndex = url.lastIndexOf(":"); }
          
          StringBuilder baseUrl = new StringBuilder();
          baseUrl.append(url.substring(0, rightIndex));
  
          // TODO This next line is pretty ugly, but it works for nearly every postgresql server.
          // If we have to add another exception to this for another database server, then I highly recommend refactoring this to a more elegant solution.
          if (POSTGRESQL.equals(databaseType(url))) { baseUrl.append("/postgres"); }
  
          int optionsIndex = url.indexOf("?");
          if (optionsIndex == -1) { optionsIndex = url.indexOf(";"); }
          if (optionsIndex != -1) { baseUrl.append(url.substring(optionsIndex)); }
  
          return baseUrl.toString();
      }
docs: Given a JDBC connection URL, generate a new connection URL to connect directly to the database server itself (ie: no database specified).
  
  @param url a JDBC connection URL
  @return a new JDBC connection URL to connect directly to the database server