错误一
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLException: No suitable driver found for jbcc:mysql://localhost:3306/mybits?useSSL=true&useUnicode=true&characterEncoding=utf8
### The error may exist in com/fanlan/Dao/UserMapper.xml
### The error may involve com.fanlan.Dao.UserDAO.selectUser
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for jbcc:mysql://localhost:3306/mybits?useSSL=true&useUnicode=true&characterEncoding=utf8
翻译
org.apache.ibatis网站.exceptions.PersistenceException异常:
###查询数据库时出错。原因:java.sql.sql异常:找不到合适的驱动程序jbcc:mysql://本地主机:3306/mybits?usesl=true&useUnicode=true&characterEncoding=utf8
###错误可能存在于com/fanlan/Dao中/用户映射器.xml
###错误可能涉及com.fanlan.Dao网站.用户dao.selectUser
###执行查询时出错
###原因:java.sql.sql异常:找不到合适的驱动程序jbcc:mysql://本地主机:3306/mybits?usesl=true&useUnicode=true&characterEncoding=utf8
原因:为配置连接池的时候,数据库的路径写错了.
解决方案:检查配置JDBC连接池的数据库账密地址是否写对
<property name="url" value="jdbc:mysql://localhost:3306/mybits?useSSL=true&useUnicode=true&characterEncoding=utf8"/>
错误二
org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.fanlan.pojo.User
翻译
org.apache.ibatis网站.builder.IncompleteElementException:找不到结果映射com.fanlan.pojo网站.用户
遇到这种错误把resultMap修改为resultType就没问题了
出现问题知道原因:
在使用mybatis进行数据库连接操作时对于SQL语句返回结果的处理通常有两种方式,一种就是resultType另一种就是resultMap,
resultType:当使用resultType做SQL语句返回结果类型处理时,对于SQL语句查询出的字段在相应的pojo中必须有和它相同的字段对应,而resultType中的内容就是pojo在本项目中的位置。
resultMap:当使用resultMap做SQL语句返回结果类型处理时,通常需要在mapper.xml中定义resultMap进行pojo和相应表字段的对应。
错误三
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
即在mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题,简单说,就是接口与xml要么是找不到,要么是找到了却匹配不到。
Mapper接口开发需要遵循以下规范:
Mapper.xml文件中的namespace与mapper接口的类路径相同。
Mapper接口方法名和Mapper.xml中定义的每个statement的id相同
Mapper接口方法的输入参数类型和mapper.xml中定义的每个sql 的parameterType的类型相同
Mapper接口方法的输出参数类型和mapper.xml中定义的每个sql的resultType的类型相同
错误四:
org.apache.ibatis.binding.BindingException: Type interface com.fanlan.Dao.UserDAO is not known to the MapperRegistry.
翻译
大概就是绑定异常:接口类型没有作mapper注册
解决方案:
查找mybatis-config.xml
文件:xml文件有没有添加到mybatis的配置文件中扫描,注册。
<!--每一个mapper.xml都需要在mybatis核心配置文件中注册-->
<mappers>
<mapper resource="com/fanlan/Dao/UserMapper.xml"/>
</mappers>
错误五
java.lang.ExceptionInInitializerError
at com.fanlan.Dao.UserMapperTest.test(UserMapperTest.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
编译输入target后输出UserMapper.xml没有编译
解决方案:
Maven由于它的约定大于配置,可能在开发过程中遇到我们写的配置文件,无法被导出或者生效的问题,尝试在Maven中加上如下配置。
在pom.xml文件内添加
<!--在build中配置resources,来防止我们资源导出失败的问题-->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>