mybatis在insert时,实体类字段为null时,报错问题
来源:互联网 发布:在数据库中储存的是 编辑:程序博客网 时间:2024/05/06 12:31
今天遇到如题的问题,就是在mybatis 插入oracle数据库空值的报的异常:
org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter. Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: java.sql.SQLException: Invalid column type ; uncategorized SQLException for SQL []; SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type
开始sql是这样写的insert into user(id,name) values(#{id},#{name})
解决方法:
一、指定插入值得jdbcType,将sql改成 insert into user(id,name) values(#{id,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR})
二、在mybatis-config.xml文件中配置一下,添加settings配置,如下:(推荐)
<configuration>......<settings> <setting name="jdbcTypeForNull" value="NULL" /></settings>......</configuration>
0 0
- mybatis在insert时,实体类字段为null时,报错问题
- EOS Platform7.6实体有字段默认值为null,调用queryEntitiesByTemplate,执行报错
- MyBatis解决字段名和实体类属性名不相同冲突问题时返回查询结果为空
- MyBatis查询返回Map时设置值为null的字段也在结果集中
- Mybatis框架实体类字段与数据库表字段不一致导致查询该字段的值一直为null
- MyBatis在字段返回为null不返回字段
- MyBatis在字段返回为null不返回字段
- Mybatis 下划线字段为NULL
- Spring boot + MyBatis 查询返回Map时设置值为null的字段也在结果集中
- MyBatis从数据库取值的时候,当某一字段为null时,如何在返回前端的时候,也包含有这个字段
- mybatis查询,返回类型为HashMap,字段为null时没返回
- 为有自增字段的实体类插入数据,报错及措施
- mybatis动态sql参数为实体类时出现的问题
- Mybatis返回HashMap时,某个字段值为null时,不会保存key
- Mybatis返回HashMap时,某个字段值为null时,不会保存key
- Mybatis返回HashMap时,某个字段值为null时,不会保存key
- Mybatis返回HashMap时,某个字段值为null时,不会保存key
- mybatis 返回HashMap是对字段值为null时不保存key
- MitraStar DSL-2401HN-T1C-GV硬件与启动信息
- SO_REUSEADDR和SO_REUSEPORT异同
- C语言中typedef关键字的作用
- 网络请求框架(OKHttp3.0)
- TensorFlow的安装以及环境配置(ubuntu16.04+1070+Anaconda)
- mybatis在insert时,实体类字段为null时,报错问题
- 平面上的点和线——Point类、Line类 (VII)
- 寻找一种易于理解的一致性算法(扩展版)
- xnamath.h 报错: 在标识符“XMConvertToRadians”的前面
- 编写一个递归方法,它返回数N的二进制表示中1的个数
- bzoj2081: [Poi2010]Beads
- js中Array和Object学习
- java线程池
- Android Studio自用插件小记