spring-security 错误:MySQLSyntaxErrorException -拒绝对用户执行选择命令

ippsafx7  于 2022-11-11  发布在  Spring
关注(0)|答案(2)|浏览(158)

我正在从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);
}

只有原生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
ego6inou

ego6inou1#

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连接的数据库未被授权使用此表。请检查您是否具有访问此数据库的正确权限。

w8biq8rn

w8biq8rn2#

回答太晚,但这是因为模式/表不正确:

.createQuery("from Medecin where login= :login and password= :password")

这里M是大写的,但是当你得到错误时:

SELECT command denied to user 'tunisie_tunisie'@'196.203.218.102' for table 'medecin'

这里是小写字母,MySQL区分大小写,请确保检查两次。

相关问题