我在测试UserTest,中间就出现几个断点
package Test;
import com.itheima.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import java.io.IOException;
import java.io.Reader;
public class UserTest { //这个地方测试错误!
@Test
public void userFindByIdTest() { //这个地方测试错误!
String resources = "mybatis-config.xml";
//创建流
Reader reader = null;
try {
//读取 mybatis-config.xml文件内容到reader对象中
reader = Resources.getResourceAsReader(resources);
} catch (IOException e) {
e.printStackTrace();
}
//初始化MyBatis数据库,创建SqlSessionFactory类的实例
SqlSessionFactory sqlMapper = new
SqlSessionFactoryBuilder().build(reader);
//创建SqlSession实例
SqlSession session = sqlMapper.openSession();
//传入参数查询,返回结果
User user = session.selectOne(
"findById", 1);
//输出结果
System.out.println(user.getUname());
//关闭session
session.close();
}
}
这是原图
出现的问题
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '=true '.
### The error may exist in com/itheima/mapper/UserMapper.xml
### The error may involve com.itheima.mapper.UserMapper.findById
### The error occurred while executing a query
### Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '=true '.
我检查过其他的文件,没有爆红,问过别人,她说我的第一个问题
Public Key Retrieval is not allowed
而后我在db.properties中添加了allowPublicKeyRetrieval=true
mysql.driver=com.mysql.cj.jdbc.Driver
mysql.url=jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC&\
characterEncoding=utf8&useUnicode=true&useSSL=false allowPublicKeyRetrieval=true
mysql.username=root
mysql.password=root
但是又出现了新问题
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near '=true '.