报如下错误
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user '13454'@'localhost' (using password: YES)
### The error may exist in com/dao/bookmapper.xml
### The error may involve com.dao.Booksmapper.querybooks
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user '13454'@'localhost' (using password: YES)
配置文件代码如下
db.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=false&useUnicode=true&characterEncoding=utf8
username=root
password=123456
连接数据库配置文件
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
</bean>
看起来明明就没有错.最后在db.properties中加上前缀就好了
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=false&useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=123456
本文详细记录了在使用MyBatis框架时遇到的数据库连接错误,具体表现为权限拒绝,通过调整配置文件中的数据库连接参数成功解决了问题。
111万+

被折叠的 条评论
为什么被折叠?



