Abstract: This article is applicable to the configuration of the dark horse Javaweb project, using mybatis to configure the database connection, using the mapper interface and its xml file to connect to the database
Problem Description
Database connection problem, display password error, unable to connect to the database
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
### The error may exist in com/itheima/mapper/BrandMapper.xml
### The error may involve com.itheima.mapper.BrandMapper.selectByPageAndCondition
### The error occurred while executing a query
### Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
Cause Analysis:
The password to connect to the database is wrong
### Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
mybatis-config.xml的配置错误,1处值与你自己的配置不一样
solution:
Enter to
mybatis-config.xml
view the codeIt can be solved by changing the value of username and password to the value you set yourself
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<package name="com.itheima.pojo"/>
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql:///db1?useSSL=false"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<!--扫描mapper-->
<package name="com.itheima.mapper"/>
</mappers>
</configuration>
Note:
1. There may be a problem in the driver attribute (the impact is not significant, but it is recommended to modify)
com.mysql.jdbc.Driver
It is version below mysql-connector-java 5 and com.mysql.cj.jdbc.Driver
version above mysql-connector-java 6.
2. The value of url is : jdbc:mysql:/// database schema name ?useSSL=false
My database looks like this: to use the table url configuration under db1 is jdbc:mysql:///db1?useSSL=false