Access denied for user 'xxx'@'localhost'

java] view plain copy

    ### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'personal_blog'  
    ### The error may exist in file [E:\1715\ssm-blog-admin\target\ssm-blog-admin\WEB-INF\classes\com\ssm\blog\dao\mapper\CategoryMapper.xml]  
    ### The error may involve com.ssm.blog.dao.CategoryDAO.getCategoryList  
    ### The error occurred while executing a query  
    ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'personal_blog'] with root cause  
     com.mysql.jdbc.exceptions.jdbc4<span style="color:#FF0000;">.MySQLSyntaxErrorException: Access denied for user 'xxx'@'localhost' to database 'personal_blog'</span>  
        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:422)  
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)  
        at com.mysql.jdbc.Util.getInstance(Util.java:386)  
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)  

Access denied for user 'xxx'@'localhost' to database where xxx may be an empty string or garbled characters. The reason for this exception is that the user name and password for logging into the database are incorrect. Check username and password. Also, if you are using configuration information read from the properties file, such as when integrating with ssh or ssm:

db.properties
[sql] view plain copy

    jdbc.driver=com.mysql.jdbc.Driver  
    jdbc.url=jdbc:mysql://localhost:3306/personal_blog?characterEncoding=utf-8  
    jdbc.username=Username  
    jdbc.password=Password  

Spring configuration:
[html]

    <!--Read configuration file-->  
        <context:property-placeholder location="classpath:db.properties" ignore-unresolvable="true"/>  
        <!--Get the data source from the configuration file-->  
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
            <property name="driverClassName" value="${jdbc.driver}"/>  
            <property name="url" value="${jdbc.url}"/>  
            <property name="username" value="${jdbc.username}"/>  
            <property name="password" value="${jdbc.password}"/>  
        </bean>  
Note that the key in the properties file is called jdbc.username, not username or user, otherwise the system environment variable will be read in xml instead of the value in properties



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325846276&siteId=291194637