title: Error: MySQLSyntaxErrorException - select command denied to user
body: <p>I'm connecting to a distant MySQL database from my web application I'm using hibernate and spring frameworks </p>
  
  <p>when I try to get element from the database, it doesn't work due to lack of privilege. </p>
  
  <pre><code> public Medecin getMedecinByLoginPassword(String login, String password) {
      System.out.println(login);
      System.out.println(password);
      List list;
      list = getSessionFactory().getCurrentSession()
         .createQuery("from Medecin where login= :login and password= :password")
         .setString("login", login).setString("password", password).list();
      return (Medecin) list.get(0);
  }
  </code></pre>
  
  <p>only Native sql works to get data from the distant database any thing else i get this error </p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'tunisie_tunisie'@'196.203.218.102' for table 'medecin'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
  at com.mysql.jdbc.Util.getInstance(Util.java:381)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
  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.sendCommand(MysqlIO.java:1936)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
  at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
  at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
  at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
  at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
  at org.hibernate.loader.Loader.doQuery(Loader.java:674)
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
  at org.hibernate.loader.Loader.doList(Loader.java:2220)
  ... 83 more
  </code></pre>