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
原创粉丝点击