title: Cannot connect to MySql database
body: <p>i am trying to test the connection to my database but i keep getting the following error</p>
  
  <pre><code>java.sql.SQLException: Access denied for user 'db'@'localhost' (using password: YES)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:798)
  at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3700)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1203)
  at com.mysql.jdbc.Connection.createNewIO(Connection.java:2572)
  at com.mysql.jdbc.Connection.&lt;init&gt;(Connection.java:1485)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at ConnectingToDB.main(ConnectingToDB.java:18)
  </code></pre>
  
  <p>My code is below. The error occurs on the line 
  "conn = DriverManager.getConnection(url+dbName,userName,password);"</p>
  
  <pre><code>public class ConnectingToDB
  {
    public static void main(String[] args) 
    {
      System.out.println("MySQL Connect Example.");
      Connection conn = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "steven";
      String driver = "com.mysql.jdbc.Driver";
      String userName = "db"; 
      String password = "db";
      try 
      {
        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url+dbName,userName,password);
        System.out.println("Connected to the database");
        conn.close();
        System.out.println("Disconnected from database");
      } 
      catch (Exception e) {
      e.printStackTrace();
     }
   }
  </code></pre>
  
  <p>}</p>