title: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
body: <p>The following code:</p>
  
  <pre><code>Class.forName("com.mysql.jdbc.Driver");
  Connection m_connection = DriverManager.getConnection("jdbc:mysql://localhost","root","root");
  </code></pre>
  
  <p>Throws this exception on <code>getConnection()</code>:</p>
  
  <pre><code>java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
      at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
      at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)
      at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
      at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
      at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:813)
      at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:47)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at db.Database.&lt;init&gt;(Database.java:91)
      at db.Main.main(Main.java:10)
  </code></pre>
  
  <p>How is this caused and how can I solve it?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>    public static void main(String[] args) throws ClassNotFoundException, ServletException, SQLException 
      {
  
          try
          {
              Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/?user=root&amp;password=rootpassword"); 
              Statement   s = (Statement) conn.createStatement();
              int result = s.executeUpdate("CREATE DATABASE databasename");
          }
  
  
          catch ( Exception e)
          {
              e.printStackTrace();
          }
  }
  </code></pre>
  
  <p>Produces :</p>
  
  <pre><code>java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
      at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
      at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)
      at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
      at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
      at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
      at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:813)
      at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:47)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
      at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at db.Main.main(Main.java:19)
  </code></pre>