捏捏你的脸 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 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效