最近在写毕设项目,用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页面