title: Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection using mySQL
body: <p>I am trying to run a simple java project to see the working of hibernate but when i am executing my code it gives a hibernate exception, i am using mysql 5.6 and eclipse neon,i even checked for grant access and everything seems to be fine, please help Here is the code: </p>
  
  <p><strong>main.java</strong></p>
  
  <pre><code>    package com.demo;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  import org.hibernate.cfg.Configuration;
  
  public class Main {
  
   public static void main(String[] args) {
      // TODO Auto-generated method stub
  
      Session session = null;
      SessionFactory sessionFactory= null;
  
      //create sessionFactory
  
      sessionFactory= new  Configuration().configure().buildSessionFactory();
  
  
      // create Session
      session=sessionFactory.openSession();
      // create and begin transaction 
  
      Transaction t = session.beginTransaction();
  
      //create contact object and set values to the object 
  
      Contact contact = new Contact();
  
      contact.setId(101);
      contact.setFirstName("Dina");
      contact.setLastName("adams");
      contact.setEmailID("dina.adams@gmail.com");
  
      // insert record by saving session
  
      session.save(contact);
  
      session.flush();
  
      // commit transaction
  
      t.commit();
  
      //close the session
  
      session.close();
  
  
  
  
    }
  
  }
  </code></pre>
  
  <p><strong>contact.java</strong></p>
  
  <pre><code>package com.demo;
  
  public class Contact {
  //properties
  
  private String firstName;
  private String lastName;
  private String emailID;
  private int id;
  public String getFirstName() {
  return firstName;
  }
  public void setFirstName(String firstName) {
  this.firstName = firstName;
   }
   public String getLastName() {
   return lastName;
  }
  public void setLastName(String lastName) {
  this.lastName = lastName;
  }
  public String getEmailID() {
  return emailID;
  } 
  public void setEmailID(String emailID) {
  this.emailID = emailID;
  }
  public int getId() {
  return id;
  }
  public void setId(int id) {
  this.id = id;
   }
  
  
   }
  </code></pre>
  
  <p><strong>hibernate.cfg.xml</strong></p>
  
  <pre><code>  &lt;?xml version='1.0' encoding='utf-8'?&gt;
     &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
  &lt;property name="hibernate.connection.driver_class"&gt; com.mysql.jdbc.Driver&lt;/property&gt;
  &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/emp&lt;/property&gt;
  &lt;property name="hibernate.connection.usename"&gt;rajesh&lt;/property&gt;  
  &lt;property name="hibernate.connection.password"&gt;Nepal123&lt;/property&gt;
  &lt;property name="hibernate.connection.poolsize"&gt;10&lt;/property&gt;
  &lt;property name="show_sql"&gt;true&lt;/property&gt;
  &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
  
  &lt;!-- Mapping file  --&gt;
  &lt;mapping resource="Contact.hbm.xml"/&gt;
  
  &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><strong>contact.hbm.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  
  &lt;hibernate-mapping&gt;
  &lt;class name = "com.demo.Contact" table="Contact"&gt;
  &lt;id column= "ID" name="id" type= "int" &gt;
  &lt;generator class = "assigned"&gt;&lt;/generator&gt;
  &lt;/id&gt;
  
  &lt;property name = "firstName"&gt;
  &lt;column name="FIRST NAME"&gt;&lt;/column&gt;
  &lt;/property&gt;
  &lt;property name="lastName"&gt;
  &lt;column name="LAST NAME"&gt;&lt;/column&gt;
  &lt;/property&gt;
  &lt;property name="emailID"&gt;
  &lt;column name ="EMAIL ID"&gt;&lt;/column&gt;
  
  &lt;/property&gt; 
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p><strong>error message:-</strong></p>
  
  <pre><code>  Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
  at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
  at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
  at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
  at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
  at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
  at com.demo.Main.main(Main.java:25)
  Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:875)
  at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1712)
  at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1228)
  at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
  at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:806)
  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:404)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
  ... 5 more
  </code></pre>