org.apache.ibatis.exceptions.PersistenceException:

  • 报错如下:
    • 错误代码提示:
    • 错误信息中的关键信息:
    • 翻译:
    • 源代码如下:
    • 错误分析:
    • 解决:
  • 报错如下:
    • 错误代码提示:
    • 错误信息中的关键信息:
    • 翻译:
    • 错误分析:
    • 解决:
      • 运行之后,发现代码还是异常!!!
      • 解决:

报错如下:

错误代码提示:

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mapper.GoodsMapper.listALL
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mapper.GoodsMapper.listALLat org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:135)at com.test.Demo.test1(Demo.java:24)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)at org.junit.runners.ParentRunner.run(ParentRunner.java:413)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mapper.GoodsMapper.listALLat org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:1031)at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:821)at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:814)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:146)... 28 moreProcess finished with exit code -1

错误信息中的关键信息:

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mapper.GoodsMapper.listALL
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mapper.GoodsMapper.listALL

翻译:

org.apache.ibatis.exceptions.PersistenceException:查询数据库错误。原因:java.lang.IllegalArgumentException: Mapped Statements集合不包含com.mapper.GoodsMapper.listALL的值原因:java.lang.IllegalArgumentException: Mapped Statements集合不包含com.mapper.GoodsMapper.listALL的值

源代码如下:

package com.test;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.InputStream;
import java.util.List;
import java.util.Map;public class Demo {@Testpublic void test1() throws IOException {String resource = "mybatis-config.xml";InputStream inputStream = Resources.getResourceAsStream(resource);SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);SqlSession session = sqlSessionFactory.openSession();System.out.println("session:"+session);List<Map> goodsList= session.selectList("com.mapper.GoodsMapper.listALL"); //错误代码//List<Map> goodsList= session.selectList("com.mapper.GoodsMapper.listAll");  //正确代码System.out.println("goodList"+goodsList);for(Map map:goodsList){System.out.println(map);}session.close();}
}

错误分析:

查询数据库错误。原因:java.lang.IllegalArgumentException: Mapped Statements集合不包含com.mapper.GoodsMapper.listALL的值。

通过代码错误提示信息,找到我们调用的xml代码文件中定义的listAll:

对比之后,不难发现错误的原因是代码中的单词: listALL 导致的错误!

解决:

将代码中的listALL修改为listAll之后,运行代码:

报错如下:

错误代码提示:

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.Driver
### The error may exist in com/mapper/StudentInfoMapper.xml
### The error may involve com.mapper.StudentInfoMapper.listAll
### The error occurred while executing a query
### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.Driverat org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:135)at com.test.StudentTest.testListAll(StudentTest.java:27)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)at org.junit.runners.ParentRunner.run(ParentRunner.java:413)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.Driverat org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:244)at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:223)at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:219)at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:95)at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:432)at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:139)at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:61)at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337)at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)... 28 moreProcess finished with exit code -1

错误信息中的关键信息:

org.apache.ibatis.exceptions.PersistenceException: Caused by:java.sql.SQLException: Error setting driver on UnpooledDataSource.Cause: java.lang.ClassNotFoundException:
Cannot find class: com.mysql.cj.jdbc.Driver

翻译:

org.apache.ibatis.exceptions.PersistenceException:引起的:UnpooledDataSource上的错误设置驱动程序。原因:java.lang.ClassNotFoundException:不能找到类:com.mysql.cj.jdbc.Driver

错误分析:

原因:java.lang.ClassNotFoundException:不能找到类:com.mysql.cj.jdbc.Driver
通过代码错误提示信息,找到我们修改的xxxxMapper.xml代码文件中定义的sql语句,发现未修改官网模板代码:

解决:

将代码中的sql语句修改为正确后运行代码:

运行之后,发现代码还是异常!!!

接着,继续分析错误原因:
UnpooledDataSource上的错误设置驱动程序。

原因:java.lang.ClassNotFoundException:

不能找到类:com.mysql.cj.jdbc.Driver 不能找到mysql驱动类

解决:

引入mysql jar包依赖,运行:

// A code block
var foo = 'bar';

org.apache.ibatis.exceptions.PersistenceException:相关推荐

  1. Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException奇葩解决方案

    项目场景: Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Er ...

  2. Mybatis快速入门的代码实现及报错处理解决org.apache.ibatis.exceptions.PersistenceException

    开发步骤: 创建普通的maven项目,导入mybatis坐标和其他的相关坐标 <!--mybatis坐标--> <dependency><groupId>org.m ...

  3. java.lang.ExceptionInInitializerError Caused by: org.apache.ibatis.exceptions.PersistenceException

    问题:在搭建mybatis时候在测试总是无法通过爆出如下错误:java.lang.ExceptionInInitializerError at com.myit.UserMapperTest.test ...

  4. Exception in thread “main“ org.apache.ibatis.exceptions.PersistenceException:报错解决

    进行MyBatis连接数据库遇到这个异常: 报错代码: Exception in thread "main" org.apache.ibatis.exceptions.Persis ...

  5. org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may

    报错显示: org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession. The error may ex ...

  6. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.

    在xml文件中碰到这样的报错的时候,有可能是你在里面使用了这种注释,编译会报错,可能这就是约定大于配置 org.apache.ibatis.exceptions.PersistenceExceptio ...

  7. SSH抛出org.apache.ibatis.exceptions.PersistenceException: 异常

    抛出的异常类容如下 如果遇到这个异常,那么肯定是你在配置事物切面时出错,或者是你的写的事物的方法名称没有和这里的配置对应: 你需要注意如下几点: 1.你的名称必须是以英文开头 2.在你用着事物方法的名 ...

  8. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyR

    异常信息: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.To ...

  9. 前端:request.js?b775:105 Uncaught (in promise) Error: nested exception is org.apache.ibatis.exceptions

    request.js?b775:105 Uncaught (in promise) Error: nested exception is org.apache.ibatis.exceptions.To ...

最新文章

  1. OpenStack Ocata Release Notes
  2. 【Android 组件化】路由组件 ( 注解处理器调试 )
  3. 常用标准库_C语言标准IO库常用函数
  4. Java EE,Docker和Maven(技术提示#89)
  5. cuda矩阵相乘_cuda初学(1):稀疏矩阵向量乘法(单精度)
  6. OpenStack 如何跨版本升级
  7. Hadoop开启Kerberos安全模式
  8. 多容器,Nginx容器灵活切换PHP版本!同时运行多个PHP容器
  9. js 实现网站来消息网站标题闪动提示 .
  10. Ubuntu安装Tensorflow及anaconda环境下使用TensorFlow
  11. mysql忘记密码如何重置密码
  12. 【历史上的今天】4 月 3 日:亚马逊卖出第一本书;世界上第一通手机电话;IBM 计算机先驱出生
  13. 海归35岁,阿里P7offer, 是否接受?
  14. redisTemplate乱码问题
  15. CEF 对CRX的支持程度
  16. key mysql_调整MySQL中的key_reads
  17. JS中的对象和方法简单剖析
  18. 转发:上海软件公司排行 (估计是2008年的吧)
  19. linux 汇编 `.eabi_attribute',交叉编译arm-none-eabi-gcc编译汇编文件(startup_stm32f10x_hd.S)遇到的有关问题(2)...
  20. 怎么确定光纤分光器的分光比?

热门文章

  1. 从kernel源代码的角度分析signal的错误用法和理解
  2. 面试让简单说一下CAS,CAS的优缺点
  3. C语言 | perror函数使用详解
  4. 求帮忙看下最优带宽怎么求解(Nadaraya-Waston)
  5. Matlab编程技巧:通过脚本获取/修改Simulink信号线参数
  6. linux dd iflag oflag,Linux dd 命令
  7. 2021年高压电工考试报名及高压电工复审考试
  8. 【交换机MAC典型配置】配置基于VLAN的MAC地址学习限制
  9. 【毕业设计】基于PLC的十字路口交通灯控制系统设计【仿真+源码+论文】
  10. 如何用VI创建.txt格式的文件?