捏捏你的脸 2023-02-27 11:04 采纳率: 100%
浏览 105
已结题

IDEA mybatis入门程序UserTest测试错误

我在测试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();
    }
}

这是原图

img

img

出现的问题

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 '.

  • 写回答

2条回答 默认 最新

  • 博客胡 2023-02-27 11:09
    关注

    useSSL和allowPublicKeyRetrieval是两个参数,需要加&

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月11日
  • 已采纳回答 3月3日
  • 创建了问题 2月27日

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法