在数据库中插入null

abc*_*abc 2 java oracle mybatis

我已经List<SomeBean>使用select声明重新审阅了.现在,我正在努力insert.这个插入语句工作正常; 但是,我无法插入空值.该表没有任何NOT NULL约束.引发以下异常:

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中插入空值?

小智 6

将此行插入MyBatis的配置文件中:

<settings>
        <setting name="jdbcTypeForNull" value="NULL" />
</settings>
Run Code Online (Sandbox Code Playgroud)


The*_*ook 5

将空参数设置为Prepared Statement或Callable语句时MyBatis需要知道jdbc类型.像这样:

#{myNullParamenter, jdbcType=VARCHAR2}
Run Code Online (Sandbox Code Playgroud)