title: Java Cannot Connect to MySQL Server
body: <p>I am trying to write a program in Java that in order to work, needs to have access to a MySQL database. Below is the code for the program so far, with the I.P. address, username, and password removed for security reasons. The problem with this code is that whenever it is run, it always fails to connect to the server, even though I know that it is running and that the password that the login information is correct. My friend found a program online that checks to see if your database can be connected to, and whenever he runs it, it always outputs "Where is your MySQL JDBC Driver?" What is the MySQL JDBC driver? I am assuming that it is the cause of my problem, but I don't know that for sure. Can anyone explain this to me?</p>
  
  <pre><code>import java.sql.*;
  
  public class main
  {
      public static void main(String[] args)
      {
          // Store the information to connect to the MySQL server in handy variables.
          String url = "jdbc:mysql://(IP REMOVED FOR SAFETY):3307/";
          String dbName = "attendance";
          String driver = "com.mysql.jdbc.Driver";
          String userName = "(USERNAME REMOVED FOR SAFETY)";
          String password = "(PASSWORD REMOVED FOR SAFETY)";
  
  
          // Now let's connect!
          try {
              Class.forName(driver).newInstance();
              Connection conn = DriverManager.getConnection(url+dbName,userName,password);
          } catch (Exception e) {
              System.out.println("Could not connect to database!");
          }
      }
  }
  </code></pre>