在数据库中插入null [英] Insert null in a database

查看:181
本文介绍了在数据库中插入null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用select语句检索了List<SomeBean>.现在,我尝试insert相同.该插入语句可以正常工作;但是,我无法插入空值.该表没有任何NOT NULL约束.引发以下异常:

I have retrived a List<SomeBean> using a select statement. Now, I am trying to insert the same. This insert statement is working fine; however, I am not able to insert null values. The table does not have any NOT NULL constraints. The following exception is raised:

org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type

如何在mybatis中插入空值?

How can I insert null values in mybatis?

推荐答案

在准备语句或可调用语句中设置空参数时,MyBatis需要知道jdbc类型.像这样:

When setting a null parameter into a Prepared Statement or a Callable Statement MyBatis needs to know the jdbc type. Like this:

#{myNullParamenter, jdbcType=VARCHAR2}

这篇关于在数据库中插入null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆