Mybatis常见低级错误_未解析的依赖项: 'org.mybatis:mybatis:jar:3.4.5-程序员宅基地

技术标签: 笔记  java  mybatis  mysql  数据库  

Mybatis错误笔记

菜鸟一枚,在学习Mybatis的时候,搭建新手项目,出了不少错误,这里铭记一下,警示自己!因为需要还原错误,所以错误的顺序是倒着进行的!
Mybatis学习笔记1,一个简单的demo

1.得到空指针null

得到空指针的问题有很多,我在项目中是因为传入的id属性是数据库中没有的,所以返回NULL类型。
在这里插入图片描述

2.serverTimezone=UTC产生的错误

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.
### The error may exist in StudentMapper.xml
### The error may involve student.getByid
### The error occurred while executing a query
### Cause: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.

这个的原因是因为时区误差导致的,我们需要把它调整成国际时差UTC 在url后面加上?serverTimezone=UTC。
在这里插入图片描述

3.JDBC驱动产生的误差

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ibatis.reflection.Reflector (file:/D:/util/Repository/org/mybatis/mybatis/3.4.6/mybatis-3.4.6.jar) to method java.lang.Class.checkPackageAccess(java.lang.SecurityManager,java.lang.ClassLoader,boolean)
WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.reflection.Reflector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

这是由于新版的mysql-connector的问题,对于jdbc的实现已经不在com.mysql.jdbc.Driver之内了,改为
com.mysql.cj.jdbc.Driver中了,所以我们修改驱动位置为

<property name="driver" value="com.mysql.cj.jdbc.Driver" />

4.密码导致的错误

这里是一个低级的错误,是因为密码错误的问题导致的!

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
### The error may exist in StudentMapper.xml
### The error may involve student.getByid
### The error occurred while executing a query
### Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

改成正确的密码就行了。

5.空行产生的错误

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in StudentMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。

产生上述问题的原因是因为你的配置文件的开头空空了一行,产生6; 不允许有匹配 “[xX][mM][lL]” 的处理指令目标,这种错误。

6.传值设定导致的错误

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in StudentMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'StudentMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias ''.  Cause: java.lang.ClassNotFoundException: Cannot find class: 

产生这种错误的原因是因为在配置传入值的类型的时候,没有设置传入值的类型或者设置错误了。

<select id="getByid" parameterType="java.lang.String" resultType="com.yuyi.Student">

设置正确的类型,尤其是parameterType, resultType一定要正确的设置!

7.驱动版本导致的错误

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 StudentMapper.xml
### The error may involve student.getByid
### 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.Driver

这是驱动版本产生的错误,记得一定要和自己的Mysql一致的版本号,不然根本找不到。

8.maven依赖产生的问题

在使用maven的时候自动导入依赖的Jar包是非常的爽,但是一旦搞错了就麻烦大了!
比如jdbc的依赖,正确的依赖声明是这样的,

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.19</version>
    </dependency>

是在mysql-connector的项目中 ,然而我去找的时候忘了这茬了,直接搜的JDBC声明格式,导入名为jdbc的项目,还找了半条的错。

在我们学习的过程中,一定要小心小心再小心,不然,都会和我前边一模一样了!
最后附上我的xml配置,配合我前边的文章可以一起看!
Hello,Mybatis的简单demo文章

mybatis.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

    <!-- 配置Mybatis的事务及数据源等等 default="development" 开发状态会显示更多的日志信息-->
    <environments default="development">
        <environment id="development">
            <!-- 使用jdbc自带的事务管理器,进行简单的事务开启和提交 -->
            <transactionManager type="JDBC" />
            <!-- 使用jdbc自带的数据库连接池 -->
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.cj.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/student?serverTimezone=UTC" />
                <property name="username" value="root" />
                <property name="password" value="123456" />
            </dataSource>
        </environment>
    </environments>
    <!-- 映射文件的路径-->
    <mappers>
        <mapper resource="StudentMapper.xml"/>
    </mappers>
</configuration>


studentmapper.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="student" >
<select id="getByid" parameterType="java.lang.String" resultType="com.yuyi.Student">

    select * from studentno where id=#{id}
</select>

    </mapper>
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_39428182/article/details/105879292

智能推荐

漏洞挖掘和利用_使用网络扫描工具搜索vsftpd ftp服务器程序的相关工具和攻击载荷,搜索出vsftpd ft-程序员宅基地

文章浏览阅读830次,点赞17次,收藏23次。快速浏览一下网页,进入“Extensions”-“User Defined Tags”,按照步骤要求设置用户名和代码,设置完成后,单击 Submit 按钮提交。

java 安卓触摸_android触控反馈的实现-程序员宅基地

文章浏览阅读209次。android触控反馈的实现芯片:RK28081框架结构Android触控反馈的实现与背光的实现方法相似,分为触控驱动、硬件抽象层、框架层及API接口,应用层系统调用。其结构如下图所示:由于framework层对硬件驱动进行了封装,应用程序以API调用的方式对硬件进行控制,应用程序只需 import android.os.Vibrator即可调用frameworkf封装的API函数实现触控反馈的功..._android java 点击反馈

python算法详解pdf百度云,python算法详解电子版-程序员宅基地

文章浏览阅读748次,点赞25次,收藏20次。最小生成树(MST):在包含 n个顶点的带权无向连通图中, 找出(n-1)条边的最小耗费生成树(权值最小)带权图:边赋以权值的图称为网或带权图,带权图的生成树也是带权的,生成树T各边的权值总和称为该树的权。最小生成树的性质:假设G=(V,E)是一个连通网,U是顶点V的一个非空子集。若(u,v)是一条具有最小权值的边,其中u∈U,v∈V-U,则必存在一棵包含边(u,v)的最小生成树。完成构造网的最小生成树必须解决下面两个问题:(1)尽可能选取权值小的边,但不能构成回路;_python算法详解电子版

用CSS实现一个三角形_前端 css写一个三角形-程序员宅基地

文章浏览阅读233次。废话不多说,直接上例子div{width: 0;height: 0;border-top: 100px solid black;border-bottom: 100px solid red;border-left: 100px solid #008c8c;border-right: 100px solid yellow;}<div></div>效果如下..._前端 css写一个三角形

Unity工具菜单翻译(二)_unity鼠标点击的翻译-程序员宅基地

文章浏览阅读1.2k次。File(文件) New Scene 新建场景 :创建一个新的游戏场景 Open Scene 打开场景 :打开一个游戏场景 Save Scene 保存场景 :保存一个游戏场景 Save Scene as 场景另存为:游戏场景另存为 New Project 新建工程文件:创建一个新的工程文件 Open Project 打开工程文件 :打开一个工程文件_unity鼠标点击的翻译

在think-cell数据表中,“撤消” (Ctrl+Z) 操作无效,怎么解决?_表格的ctrl+z没反应是什么-程序员宅基地

文章浏览阅读270次。解决方案您随时可以撤消 PowerPoint 中的更改。关闭数据表以返回到 PowerPoint,然后单击快速访问工具栏上的撤消按钮(或按 Ctrl+Z )。幻灯片上的图表将还原为先前的状态,并相应撤消图表的数据表中的更改。说明think-cell 的数据表是 Excel 表格。您更改某些数据后,在 PowerPoint 幻灯片更新时会保存该数据表。遗憾的是,Excel 会在保存时放弃其撤消缓冲区。若直接使用 Excel,在保存工作簿后,也会出现该行为。..._表格的ctrl+z没反应是什么

随便推点

Net操作Excel(终极方法NPOI)_操作excle的最快方法是npoi-程序员宅基地

文章浏览阅读403次。前言Asp.net/C#操作Excel已经是老生长谈的事情了,可下面我说的这个NPOI操作Excel,应该是最好的方案了,没有之一,使用NPOI能够帮助开发者在没有安装微软Office的情况下读写Office 97-2003的文件,支持的文件格式包括xls, doc, ppt等。NPOI是构建在POI 3.x版本之上的,它可以在没有安装Office的情况下对Word/Excel文档进行_操作excle的最快方法是npoi

SQL文件转换为CSV文件(附Navicat下载)_sql文件转换成csv-程序员宅基地

文章浏览阅读4.9k次,点赞4次,收藏25次。在日常处理涉及到数据库的案件中,我们经常能够获取一些SQL文件,那么该如何处理这些SQL文件呢?首先,我们得到了多个SQL文件。接着,我们就要尝试在本地搭载一个新的数据库环境。一、Windows下安装MySQL:1、在MySQL的官方网站中下载得到MySQL的ZIP包,并解压到指定目录。2、在解压后的MySQL文件根目录下新建my.ini文件(MySQL的配置文件),my.ini文件内容如下:这里需要将basedir与datadir路径改成MySQL的解压路径。3、找到CMD命令提示符,以管理员_sql文件转换成csv

vue-cli安装与问题code ERESOLVE npm ERR ERESOLVE unable to resolve dependency tree处理_peer webpack@"^2.2.0" from extract-text-webpack-pl-程序员宅基地

文章浏览阅读2.7k次,点赞3次,收藏4次。Vue学习一、安装vue-cli下载地址: 下载 | Node.js 中文网 安装的时候一直下一步直到结束确认是否安装成功: 在cmd中运行node -v命令,查看是否能够输出版本号 在cmd中运行npm -v命令,查看是否能够输出版本号 node -vnpm -v安装Node.js淘宝镜像加速器(cnpm)npm install cnpm -g //-g 全局安装安装vue-cli -gcnpm install vue-cli -gvue l_peer webpack@"^2.2.0" from [email protected]

银行营业网点管理系统——dao包(BranchesDao)-程序员宅基地

文章浏览阅读579次。package BranchesMgr.dao;import java.util.List;import BranchesMgr.entity.Branches;/** * 网点信息表的借口 * @author Administrator * */public interface BranchesDao { //查询所有网点信息 List&lt;Branches&gt; ..._银行管理系统dao模式

A new Nova service: nova-conductor_timed out waiting for nova-conductor. is it runnin-程序员宅基地

文章浏览阅读735次。Come from: http://russellbryantnet.wordpress.com/2012/11/19/a-new-nova-service-nova-conductor/The Grizzly release of OpenStack Nova will have a new service, nova-conductor. The service was dis_timed out waiting for nova-conductor. is it running? or did this service sta

设计考勤打卡的心得体会_125k 打卡-程序员宅基地

文章浏览阅读3.8k次。&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;在今年8-10份,独自一个人担任促销管理系统的考勤系统的开发。从需求理解、到表设计、到API接口的输出,bug的修复到最后的完工。今天停下脚步总结一下。在整个过程中,给我最深刻的时最开始的表设计。考勤打卡每个企业个性化比较强,我的这个项目是促销人员使用的考勤打卡系统,模式:班次–排版-考勤。 每个人各不相同,不具备使用考勤组的。一个促销人员一天..._125k 打卡

推荐文章

热门文章

相关标签