Prasad Paravatha
Prasad Paravatha

Reputation: 618

MyBatis inserting null to a DB2 DATE column

Using MyBatis (Version 3.2.5) I am trying to Update a DB2 DATE column with NULL, but getting this below error

org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #5 with JdbcType NULL . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: com.ibm.db2.jcc.c.SqlException: [ibm][db2][jcc][10281][10295] JDBC type 0 is not yet supported.
; uncategorized SQLException for SQL []; SQL state [null]; error code [-99999]; [ibm][db2][jcc][10281][10295] JDBC type 0 is not yet supported.; nested exception is com.ibm.db2.jcc.c.SqlException: [ibm][db2][jcc][10281][10295] JDBC type 0 is not yet supported.

I tried the below suggestions, but they are not working for me

MyBatis - jdbcTypeForNull Oracle

Upvotes: 1

Views: 1940

Answers (2)

Prasad Paravatha
Prasad Paravatha

Reputation: 618

Found the solution..

in mybatis-config.xml, I had

<setting name="jdbcTypeForNull" value="NULL" />

I changed it like below.

<configuration>
    <settings>
        <setting name="jdbcTypeForNull" value="DATE" />             
    </settings>    
</configuration>

Upvotes: 0

blackwizard
blackwizard

Reputation: 2044

The exception is thrown from line 39 of BaseTypeHandler.

Set a break point to check the current value of jdbcType.TYPE_CODE. It should work fine when it equals java.sql.Types.TIMESTAMP (93), that might not be the case.

So if not the case, Expected actual type for this being DateTypeHandler. You might then have to define your own DateTypeHandler, just extend it and override method setParameter from BaseTypeHandler, actually just replace variable jdbcType.TYPE_CODE with forced java.sql.Types.TIMESTAMP. To use it by default for all Date parameters, register it in the typeHandler section of mybatis-config.xml (or Spring). Otherwise set the typeHandler attribute for concerned parameter in the insert statement.

Upvotes: 1

Related Questions