title: How to solve error: java.sql.SQLNonTransientConnectionException: Could not create connection to database server
body: <p>this is my code</p>
  
  <pre><code>private String dbURL;
  private String dbUsername = "root";
  private String dbPassword = "root1234";
  private String URL = "localhost";
  private String port = "3306";
  private String dbName = "university";
  private Connection con;
  
  private void connectToDataBase() throws ClassNotFoundException, SQLException {
  
      dbURL = "jdbc:mysql://" + URL + ":" + port + "/" + dbName + "?verifyServerCertificate=false";
      Properties p = new Properties();
      p.setProperty("user", dbUsername);
      p.setProperty("password", dbPassword);
      p.setProperty("useSSL", "false");
      p.setProperty("autoReconnect", "true");
      Class.forName("com.mysql.cj.jdbc.Driver");
  
      con = DriverManager.getConnection(dbURL, p);
  </code></pre>
  
  <p>and i encountered this problem
  java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
  <a href="https://i.stack.imgur.com/huC2N.png" rel="nofollow noreferrer">enter image description here</a></p>