学MyBatis时遇到的两个错误

刚学到MyBatis,感觉照着敲出来的,却出不来效果,报错了。错误提示如下方

网上搜索相关错误,搜到是xml文件配置时出错了。对比前辈们出错的位置,然后通过标红错误提示找到了xml文件的第二行,如图1。感觉没什么问题,唯一的不同的就是我多写了第一行。于是删除了第一行的内容,其他都没变,还是出现同样的错误。于是把第一行空行去掉,第二行往上移,变成第一行。终于没错了!!

看来xml配置文件,声明一定要在第一行。而且开头不能空行。文件中间语句间可以空行

图1

以下是部分错误提示信息:

org.apache.ibatis.exceptions.PersistenceException:

### Error building SqlSession.

### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。

=========================

另外还有一个错误是因为url写错了,由于老师的命名是localhost,我命名写的是@locohost如图2,所以在url里也加了@。去掉@就对了。至于为什么我也不知道-_-||。也是通过下方标红的错误提示位置定位出来的。

图三的标红位置也容易出错,&后要记得加amp;啊。

图2

图3

以下是部分错误提示信息:

org.apache.ibatis.exceptions.PersistenceException:

### Error getting a new connection. Cause: com.mysql.jdbc.exceptions.jdbc4.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.

### Cause: com.mysql.jdbc.exceptions.jdbc4.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: java.net.UnknownHostException: @localhost

所以学习中遇到了问题,找不到大神的时候,就要学会自己从错误提示中找到关键词,不怕出错,只要每次都积累起来,见多了,就会熟能生巧。

这是我花了近1个小时解决的两个错误。成就感还是有的!!哈哈哈哈!

发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章