title: JDBC Connection: access denied
body: <p>I am trying to get the JDBC connection with mysql over SSL.
  I have already imported the valid certificate to cacertsSSL.jks file.
  Still i am not able to connect.</p>
  
  <p>Is there a way out without extending or changing the Driver?</p>
  
  <pre><code>public static void getMysqlConnection() {
      Connection connection = null;
      try {
  
        Class.forName("com.mysql.jdbc.Driver");
        Driver driver = DriverManager.getDriver(URL);
        DriverPropertyInfo[] info = driver.getPropertyInfo(URL, null);
  
        String URL = "jdbc:mysql://myHost:3307/myDB?verifyServerCertificate=false&amp;amp;requireSSL=true&amp;amp;useSSL=true";
        String USER = "myUser";
        String PASSWORD = "myPwd";
  
        System.setProperty("javax.net.ssl.keyStore", "C:\\Development\\cacertsSSL.jks");
        System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
        System.setProperty("javax.net.ssl.trustStore", "C:\\Development\\cacertsSSL.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
  
        Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
        System.out.println(conn);
      } catch (Exception e) {
        System.out.println("Connection Failed! Check output console");
        e.printStackTrace();
        return;
      }
    }
  </code></pre>
  
  <p>Below is connection error Stack Trace</p>
  
  <pre><code>java.sql.SQLException: Access denied for user 'myuser'@'myHost' (using password: YES)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
  at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
  at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:718)
  at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:46)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
  at java.sql.DriverManager.getConnection(DriverManager.java:582)
  at java.sql.DriverManager.getConnection(DriverManager.java:154)
  at com.test.Test1.getMysqlConnection(Test1.java:152)
  at com.test.Test1.main(Test1.java:25)
  </code></pre>
  
  <p>Answer:
   Here is what made it work:</p>
  
  <pre><code>  String URL = "jdbc:mysql://myHost:3307/myDB?useSSL=true";
    String USER = "myUser";
    String PASSWORD = "myPwd";
  
    System.setProperty("javax.net.ssl.trustStore", "C:\\Development\\cacertsSSL.jks");
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
  </code></pre>
  
  <p>Only TrustStore is sufficient in this case and only useSSL worked in my case.
  Thanks.</p>