2015-02-08 36 views
1

我连接到一个遥远的MySQL数据库从我的web应用程序我使用Hibernate和Spring框架错误:MySQLSyntaxErrorException - 选择命令拒绝用户

当我尝试从数据库中获取元素,这不是”由于缺乏特权而无法工作。

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

只有本地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
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: SELECT command denied to user 'tunisie_tunisie'@'196.203.218.102' for table 'medecin' 

这清楚地指出数据库你得到的数据试图用主机ip 196.203.218.102的用户名tunisie_tunisie连接未被授权使用此表。检查您是否拥有访问此数据库的正确权限。

+0

我已经讨论过,与Web主机管理器,但他肯定,问题是在我的代码我可以建立与其他Java应用程序的数据库连接并获取数据,但从这个应用程序它不起作用 – JEEDEV 2015-02-09 08:58:00

+0

确保如果您可以使用数据库详细信息进行连接。您可以使用此代码来测试[链接](http://www.ekiras.com/2014/09/create-mysql-database-jdbc-connection-in-java.html)。如果您可以通过此代码连接到数据库,那么您需要检查您的代码。首先检查您是否能够使用此代码连接数据库。 – 2015-02-09 10:00:53

+0

连接成功建立 我认为这是一个由于spring-security框架引起的特权问题 – JEEDEV 2015-02-09 12:48:42