title: BatchUpdateException is thrown when inserting null values for decimal fields into MS SQL Server
body: <p>We are using the standard  Spring Batch <code>JdbcBatchItemWriter</code> to insert data into <strong>MS SQL Server</strong>.
  The data to be inserted (the output from the item processor) is contained in a <code>Map&lt;String,String&gt;</code>, which holds the column names and values.</p>
  
  <p>When the map contains null values (represented as an empty string "") for columns which are defined as Decimal (to be more specific, (decimal(19,5),null), the following exception is thrown:</p>
  
  <pre><code>java.sql.BatchUpdateException: Error converting data type nvarchar to numeric
  </code></pre>
  
  <p>Numeric fields which are not decimal work fine.</p>
  
  <p>The driver is: <code>net.sourceforge.jtds.jdbc.Driver</code></p>
  
  <p>The following dll is used to connect to SQL Server: <code>ntlmauth.dll</code></p>
  
  <p>The Spring Batch item writer configuration is similar to the following:</p>
  
  <pre><code>&lt;bean id="itemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter"&gt;
     &lt;property name="dataSource" ref="..." /&gt;
     &lt;property name="sql" value="${...}" /&gt;
     &lt;property name="itemPreparedStatementSetter"&gt;
        &lt;bean class="org.springframework.batch.item.database.support.ColumnMapItemPreparedStatementSetter" /&gt;
     &lt;/property&gt;
     &lt;property name="itemSqlParameterSourceProvider"&gt;
              &lt;bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" /&gt;
     &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Here is the full stack trace:</p>
  
  <pre><code>]; Error converting data type nvarchar to numeric.; nested exception is java.sql.BatchUpdateException: Error converting data type nvarchar to numeric.
      at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:245)
      at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:603)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:615)
      at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:884)
      at org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(NamedParameterBatchUpdateUtils.java:40)
      at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate(NamedParameterJdbcTemplate.java:303)
      at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate(NamedParameterJdbcTemplate.java:298)
      at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:175)
      at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
      at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
      at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274)
      at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199)
      at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
      at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:395)
      at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
      at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:267)
      at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)
      at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)
      at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
      at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
      at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253)
      at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
      at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:141)
      at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
      at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
      at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:151)
      at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:130)
      at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
      at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)
      at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134)
      at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
      at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127)
      ...
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64)
      at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
      at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:722)
  Caused by: java.sql.BatchUpdateException: Error converting data type nvarchar to numeric.
      at net.sourceforge.jtds.jdbc.JtdsStatement.executeBatch(JtdsStatement.java:944)
      at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
      at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:899)
      at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:884)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587)
  </code></pre>
  
  <p>Any assistance is greatly appreciated.</p>