Weird
Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘Lin’@‘localhost’ (using password: YES)
General situation
- Generally it is a permission problem (the solution below is others)
https://blog.csdn.net/chuyouyinghe/article/details/79225972
Strange situation
- I used DriverManagerDataSource in spring-jdbc to get the data source
The following is the configuration file of jdbc:
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/student
username=root
password=root
The following is the configuration of the data source in spring:
<!--配置dataSource-->
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driverClassName}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
</bean>
My test code:
running results:
Find the reason
I use the new method to create objects, instead of spring Ioc.
This will run without problems.
result
Just change the ${username} in the configuration file to another name.
Once you change it back to username, an error will be reported. After checking it for a long time, I don't know why, but the problem is solved. Does anyone know who can give me some advice?