{"record":{"id":"2e37bc9e992d38a8","repo":"mybatis/mybatis-3","slug":"error-setting-null-for-parameter-i-with-j","errorCode":null,"errorMessage":"Error setting null for parameter #\" + i + \" with JdbcType \" + jdbcType + \" . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: \" + e","messagePattern":"Error setting null for parameter #\" \\+ i \\+ \" with JdbcType \" \\+ jdbcType \\+ \" \\. Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property\\. Cause: \" \\+ e","errorType":"exception","errorClass":"TypeException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/type/BaseTypeHandler.java","lineNumber":67,"sourceCode":"   *          the new configuration\n   *\n   * @deprecated Since 3.5.0 - See https://github.com/mybatis/mybatis-3/issues/1203. This property will remove future.\n   */\n  @Deprecated\n  public void setConfiguration(Configuration c) {\n    this.configuration = c;\n  }\n\n  @Override\n  public void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException {\n    if (parameter == null) {\n      if (jdbcType == null) {\n        throw new TypeException(\"JDBC requires that the JdbcType must be specified for all nullable parameters.\");\n      }\n      try {\n        ps.setNull(i, jdbcType.TYPE_CODE);\n      } catch (SQLException e) {\n        throw new TypeException(\"Error setting null for parameter #\" + i + \" with JdbcType \" + jdbcType + \" . \"\n            + \"Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. \"\n            + \"Cause: \" + e, e);\n      }\n    } else {\n      try {\n        setNonNullParameter(ps, i, parameter, jdbcType);\n      } catch (Exception e) {\n        throw new TypeException(\"Error setting non null for parameter #\" + i + \" with JdbcType \" + jdbcType + \" . \"\n            + \"Try setting a different JdbcType for this parameter or a different configuration property. \" + \"Cause: \"\n            + e, e);\n      }\n    }\n  }\n\n  @Override\n  public T getResult(ResultSet rs, String columnName) throws SQLException {\n    try {\n      return getNullableResult(rs, columnName);","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/type/BaseTypeHandler.java#L49-L85","documentation":"MyBatis successfully decided to call ps.setNull(i, jdbcType.TYPE_CODE) but the JDBC driver itself rejected that type code with a SQLException, which BaseTypeHandler wraps in this TypeException. The original driver error is attached as the cause. The classic case is Oracle refusing java.sql.Types.OTHER for NULL columns.","triggerScenarios":"A null parameter is sent with jdbcType OTHER (the MyBatis default for jdbcTypeForNull) to a driver that only accepts concrete types — Oracle, older DB2, some SQL Server configurations.","commonSituations":"Switching an application from MySQL/PostgreSQL (tolerant of OTHER) to Oracle; upgrading a driver that used to silently coerce Types.OTHER; setting a jdbcType in the mapper that the driver's setNull does not support.","solutions":["Set <setting name=\"jdbcTypeForNull\" value=\"NULL\"/> in the MyBatis configuration (sends Types.NULL instead of OTHER)","Or pin a concrete type on the offending parameter: #{value,jdbcType=VARCHAR}","Read the embedded Cause to confirm which type code the driver rejected and adjust that parameter's jdbcType accordingly"],"exampleFix":"// before (mybatis-config.xml)\n<settings><setting name=\"jdbcTypeForNull\" value=\"OTHER\"/></settings>\n\n// after\n<settings><setting name=\"jdbcTypeForNull\" value=\"NULL\"/></settings>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ... } catch (TypeException e) {\n  if (e.getCause() instanceof SQLException && e.getMessage().contains(\"Error setting null\")) {\n    // switch that parameter to jdbcType=NULL or set jdbcTypeForNull=NULL, then retry\n  }\n}","preventionTips":["On Oracle, always configure <setting name=\"jdbcTypeForNull\" value=\"NULL\"/>","Smoke-test insert/update paths with null values against the production driver","Pin driver versions and re-test null handling after driver upgrades"],"tags":["mybatis","jdbc","oracle","null","configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}