MyBatis初学常见运行报错

错误核心配置文件(mybatis-config.xml)没有 注册映射文件(EmpMapper.xml)

org.apache.ibatis.binding.BindingException: Type interface com.jx.dao.EmpMapper is not known to the MapperRegistry.

如何修改  在核心配置文件中注册映射文件 mybatis-config.xml

    <!--指定  映射器-->

    <mappers>

        <mapper resource="mapper/EmpMapper.xml"/>

        <mapper resource="mapper/DeptMapper.xml"/>

        <mapper resource="mapper/EmpPlusMapper.xml"/>

</mappers>

错误2 数据库服务未打开

org.apache.ibatis.exceptions.PersistenceException:

### Error querying database.  Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

### The error may exist in mapper/EmpMapper.xml

### The error may involve com.jx.dao.EmpMapper.findAllEmp2

### The error occurred while executing a query

### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

...

Caused by: java.net.ConnectException: Connection refused: connect

错误解决方案  打开mysql服务

Win+R  输入 services.msc

 

 

错误3  SQL语句编写错误

org.apache.ibatis.exceptions.PersistenceException:

### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'emp e,dept d

        WHERE e.deptno=d.deptno' at line 8

### The error may exist in mapper/EmpMapper.xml

### The error may involve defaultParameterMap

### The error occurred while setting parameters

### SQL: SELECT                   e.empno,e.ename,e.job,e.mgr,e.hiredate,e.sal,e.comm,e.deptno      ,                   d.deptno, d.dname, d.loc               form emp e,dept d         WHERE e.deptno=d.deptno

### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'emp e,dept d

        WHERE e.deptno=d.deptno' at line 8

映射文件当中编写的sql语句有语法错误

检查SQL语句 找到错误

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值