用hibernate操作mysql数据库,出现java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)异常,请问高手是什么原因,我的用户名和密码可以确保配置正确,而且root'@'localhost在mysql的manger链接测试也成功,为什么程序运行会程序上面异常?不要跟我说用户名和密码错误MySQL数据库异常

解决方案 »

  1.   

    是的,我在mysql的管理管理工具用相应的用户名和密码,连接测试成功,但是真正程序运行hibernate操作数据却出现上述异常,我的配置可以保证每配错用户名和密码,真不知是什么原因?
      

  2.   

    //各位大神,我的hibernate配置如下
    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="fileEncoding" value="utf-8" />
    <property name="locations">
    <list>
    <value>classpath*:db.properties</value>
    </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="true"></property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">
    <value>${jdbc.driverClassName}</value>
    </property>
    <property name="url">
    <value>${jdbc.url}</value>
    </property>
    <property name="username">
    <value>${jdbc.username}</value>
    </property>

    <property name="password">
    <value>${jdbc.password}</value>
    </property>
     
    <property name="defaultAutoCommit">
    <value>${jdbc.defaultAutoCommit}</value>
    </property>
    <property name="maxActive">
    <value>${jdbc.maxActive}</value>
    </property>
    </bean>
    <!-- 开启Spring Required annotation -->
    <bean
    class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
    <bean
    class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> <bean id="jdbcTemplate " class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    </bean>


    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="net.spring.**.entity" />
    <property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.MySQLDialect
    <!-- hibernate.hbm2ddl.auto=update -->
    hibernate.show_sql=true
    hibernate.format_sql=false
    hibernate.connection.username=sh_test
    hibernate.connection.password=1234
    </value>
    </property>


    </bean>//===================数据库properties==============================================
    #configuration JDBC Connection
    jdbc.driverClassName=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/webqq?useUnicode=true&amp;characterEncoding=UTF-8
    jdbc.username=sh_test
    jdbc.password=1234
    jdbc.defaultAutoCommit=false
    jdbc.maxActive=5
    jdbc.dialect=org.hibernate.dialect.MySQLDialect
      

  3.   

    Access denied 一般看你使用的用户有没有赋予连接权限,或者连接有没有配置正确
      

  4.   

    我的用户名和密码都是正确的,权限也给了啊,为什么直接用底层的jdbc可以访问,用hibernate框架就不可以了?