在数据库中插入null [英] Insert null in a database
问题描述
我已经使用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屋!