错误:MySQLSyntaxErrorException - 选择拒绝用户的命令

时间:2015-02-08 18:23:52

标签: mysql spring hibernate java-ee spring-security

我从我的Web应用程序连接到远程MySQL数据库我正在使用hibernate和spring框架

当我尝试从数据库中获取元素时,由于缺少权限,它不起作用。

 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);
}

只有Native sql能够从远程数据库获取数据,否则我会收到此错误

错误

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

1 个答案:

答案 0 :(得分:1)

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'tunisie_tunisie'@'196.203.218.102' for table 'medecin'

这清楚地表明您尝试使用主机IP tunisie_tunisie上的用户名196.203.218.102连接的数据库无权使用此表。检查您是否具有访问此数据库的正确权限。