title: Can't connect to MySQL database: No suitable driver found
body: <p>I'm having some troubles with java and jdbc.
  In particular, while my code perfectly works in a NetBeans project, when i try to execute it on a terminal or on my ubuntu vps (which is where i need it to work) i always get this exception:</p>
  
  <p><code>java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/quakes</code></p>
  
  <p>First thing first: yes, i'm adding the jdbc .jar to the execute command and the compile command; Yes, i've even tried to add </p>
  
  <p><code>Class.forName("com.mysql.jdbc.Driver");</code>,</p>
  
  <p>but I always get a <code>ClassNotFoundException: com.mysql.jdbc.Driver</code> exception
  The .jar i'm using is the exact same that i use in the NetBeans project, so i know i have the right thing, and even downloading it again from the official site won't change a thing.
  Yes, the database exists, and the result doesn't change if i try to connect to another db.
  I also tried switching to postgresql (yes, i didn't forget to change the url), but to no avail, it still can't find the driver.
  With this, i'm guessing that the actual error is in the compile/execute commands, but even them should be ok:</p>
  
  <p><code>javac *.java &lt;-cp mysql-connector-java-5.1.41-bin.jar &gt;</code> (the &lt;> parenthesis means that i tried compiling with and without specifying the classpath);</p>
  
  <p><code>java TAW -cp mysql-connector-java-5.1.41-bin.jar</code>,</p>
  
  <p>In case you want to see it, here's the method that tries to connect to the database:</p>
  
  <pre><code>public Connection getConnection() throws SQLException {
      if (conn == null) {
          conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+
          this.dbname,this.user,this.pass);
      }
      return conn;
  }
  </code></pre>
  
  <p>Does anyone have any idea on why this happens?</p>