SpringBoot搭建基于Restful接口,MyBatis连接Mysql异常:at com.ritzCourse.service.impl.StuServiceimpl.getStuInfo

最近在写毕设项目,用IDEA搭建SpringBoot项目时,Mybatis连接MySQL数据库是报异常,最终发现是是MySQL版本号的问题,我连接用的是8.0的Mysql ,结果Maven下载的却是MYSQL 5.1.46的版本依赖;最终修改后,运行发现无异常

mysql 5用的驱动是com.mysql.jdbc.Driver

mysql 8用的驱动是com.mysql.cj.jdbc.Driver

*我的pom.xml里用的就是5.1.46,但我导入的是8.0的 jar

所报异常:
at com.ritzCourse.service.impl.StuServiceimpl.getStuInfo StuServiceimpl.java:20

IDEA里SpringBoot项目,mybatis链接mysql数据库时报以下错误

十一月 22, 2020 4:34:43 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Tomcat]
十一月 22, 2020 4:34:43 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet engine: [Apache Tomcat/9.0.19]
十一月 22, 2020 4:34:43 下午 org.apache.catalina.core.ApplicationContext log

at com.ritzCourse.service.impl.StuServiceimpl.getStuInfo StuServiceimpl.java:20

java.sql.SQLException: com.mysql.cj.jdbc.Driver
	at com.sun.proxy.$Proxy57.selectList(Unknown Source) [na:na]
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230) [mybatis-spring-2.0.0.jar:2.0.0]
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:144) [mybatis-3.5.0.jar:3.5.0]
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:77) [mybatis-3.5.0.jar:3.5.0]
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) [mybatis-3.5.0.jar:3.5.0]
	at com.sun.proxy.$Proxy58.getAllUser(Unknown Source) [na:na]
	at com.feifan.Service.UserServiceIpml.getAllUser(UserServiceIpml.java:17) [classes/:na]
	at com.feifan.Controller.DemoController.getAllUser(DemoController.java:25) [classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) [spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) [spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) [spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) [spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]

IDEA中导入的8.0版本

最终修改pom中依赖版本号后成功显示数据库前台Post调用MySQL页面


在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值