title: JDBC MySQL - Java unable to connect to database server
body: <p>I have a local MySQL running on the default port, but for some reason my code can't connect to it. restdb is the database name I'm trying to connect to. I can do queries from Workbench, so I'm pretty positive the database itself is up.</p>
  
  <p>I have a maven project, and the mysql-connector (mysql-connector-java-8.0.11.jar) is in my Maven Dependencies. Is this the wrong place?</p>
  
  <p>Here is my code. It fails at getConnection. In my error log it tells me:</p>
  
  <pre><code>Could not create connection to database server. Attempted reconnect 3 times. Giving up.
  
  private Connection getConnection()
  {
      Connection conn = null;
      String url = "jdbc:mysql://localhost:3306/restdb?autoReconnect=true&amp;useSSL=true";
      String username = "root";
      String password = "password";
      try
      {           
          DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
          conn = DriverManager.getConnection(url, username, password);
      } catch (Exception e)
      {
          System.err.println(e.getMessage());
      }
      return conn;
  }
  </code></pre>