title: Issues with JDBC MySQL URLs and special chars
body: <p>I have currently run into a problem with special chars like <code>:</code> in the URL for a JDBC MySQL connection. Since it is an URL I thought I could just URL encode the strings I supply (for like the password). However it is not working.</p>
  
  <p>I tried the following code</p>
  
  <pre><code>public class DatabaseConnection {
      protected static String urlEncode(String toEncode) {
          try {
              return URLEncoder.encode(toEncode, "UTF-8");
          } catch (UnsupportedEncodingException e) {
              // Won't happen anyways!
              e.printStackTrace();
  
              return null;
          }
      }
  
      public DatabaseConnection(String host, int port, String database, String user, String password)
              throws SQLException {
          StringBuilder connectionURL = new StringBuilder();
  
          connectionURL.append("jdbc:mysql://").append(urlEncode(host)).append(':').append(port).append('/')
                  .append(urlEncode(database)).append("?user=").append(urlEncode(user)).append("&amp;password=")
                  .append(urlEncode(password));
  
          connect(connectionURL);
      }
  }
  </code></pre>
  
  <p><em>(The connect method works well. It is dependend on the library I use so supplying the code won't do much.)</em></p>
  
  <p>The code works well as long as password (Or any other string) doesn't contain <code>:</code>. It could be that other chars don't work either but I haven't tested that yet. The <code>:</code> gets escaped to <code>%3A</code>. And then the login fails. I verified several times that the password is correct. (Tested it by connection to the MySQL server over the command line)</p>