title: Spring Batch- Read an CSV file and write to MySQL Database giving error for int and Date datatypeses
body: <p>I'm trying to execute Spring Batch Example – CSV File To MySQL Database.</p>
  
  <p><strong>when im running the App.java the following error it is displaying.</strong></p>
  
  <pre><code>java.lang.NumberFormatException: Unparseable number: Clicks
  java.lang.IllegalArgumentException: Unparseable date: "Order Date", format: [dd/MM/yyyy]
  </code></pre>
  
  <p>Can anyone pls let me know where i have done mistake..</p>
  
  <p>Source Code :</p>
  
  <p>report.csv</p>
  
  <pre><code>OrderDate,Impressions,Clicks,Earning
  6/1/13, "139,237", 37, 227.21
  6/2/13, "149,582", 55, 234.71
  6/3/13, "457,425", 132, 211.48
  6/4/13, "466,870", 141, 298.40
  6/5/13,"472,385",194,281.35
      ......
  </code></pre>
  
  <p>resources/spring/batch/config/database.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/jdbc 
      http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd"&gt;
  
    &lt;!-- connect to database --&gt;
    &lt;bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/test" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="" /&gt;
    &lt;/bean&gt;
  
    &lt;bean id="transactionManager"
      class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" /&gt;
  
    &lt;!-- create job-meta tables automatically --&gt;
    &lt;jdbc:initialize-database data-source="dataSource"&gt;
      &lt;jdbc:script location="org/springframework/batch/core/schema-drop-mysql.sql" /&gt;
      &lt;jdbc:script location="org/springframework/batch/core/schema-mysql.sql" /&gt;
    &lt;/jdbc:initialize-database&gt;
  
  &lt;/beans
  </code></pre>
  
  <p>resources/spring/batch/config/context.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"&gt;
  
    &lt;!-- stored job-metadata in database --&gt;
    &lt;bean id="jobRepository"
      class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="transactionManager" ref="transactionManager" /&gt;
      &lt;property name="databaseType" value="mysql" /&gt;
    &lt;/bean&gt;
  
    &lt;!-- stored job-metadata in memory --&gt;
    &lt;!-- 
    &lt;bean id="jobRepository"
      class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean"&gt;
      &lt;property name="transactionManager" ref="transactionManager" /&gt;
    &lt;/bean&gt;
     --&gt;
  
    &lt;bean id="jobLauncher"
      class="org.springframework.batch.core.launch.support.SimpleJobLauncher"&gt;
      &lt;property name="jobRepository" ref="jobRepository" /&gt;
    &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>resources/spring/batch/jobs/job-report.xml</p>
  
  <pre><code> &lt;beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:batch="http://www.springframework.org/schema/batch" 
          xmlns:task="http://www.springframework.org/schema/task"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.springframework.org/schema/batch
          http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"&gt;
  
        &lt;bean id="report" class="com.mkyong.model.Report" scope="prototype" /&gt;
  
        &lt;batch:job id="reportJob"&gt;
          &lt;batch:step id="step1"&gt;
            &lt;batch:tasklet&gt;
              &lt;batch:chunk reader="cvsFileItemReader" writer="mysqlItemWriter"
                  commit-interval="2"&gt;
              &lt;/batch:chunk&gt;
            &lt;/batch:tasklet&gt;
          &lt;/batch:step&gt;
        &lt;/batch:job&gt;
  
        &lt;bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader"&gt;
  
          &lt;!-- Read a csv file --&gt;
          &lt;property name="resource" value="classpath:cvs/report.csv" /&gt;
  
          &lt;property name="lineMapper"&gt;
              &lt;bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper"&gt;
                &lt;!-- split it --&gt;
                &lt;property name="lineTokenizer"&gt;
                      &lt;bean
                    class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"&gt;
                      &lt;property name="names" value="date,impressions,clicks,earning" /&gt;
                  &lt;/bean&gt;
                &lt;/property&gt;
                &lt;property name="fieldSetMapper"&gt;   
  
  
                    &lt;!-- map to an object --&gt;
     &lt;bean class="com.mkyong.ReportFieldSetMapper" /&gt;     
                &lt;/property&gt;
  
                &lt;/bean&gt;
            &lt;/property&gt;
  
        &lt;/bean&gt;
  
        &lt;bean id="mysqlItemWriter"
          class="org.springframework.batch.item.database.JdbcBatchItemWriter"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="sql"&gt;
            &lt;value&gt;
                  &lt;![CDATA[        
                      insert into RAW_REPORT(DATE,IMPRESSIONS,CLICKS,EARNING) 
                  values (:date, :impressions, :clicks, :earning)
                  ]]&gt;
            &lt;/value&gt;
          &lt;/property&gt;
          &lt;!-- It will take care matching between object property and sql name parameter --&gt;
          &lt;property name="itemSqlParameterSourceProvider"&gt;
              &lt;bean
              class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" /&gt;
          &lt;/property&gt;
        &lt;/bean&gt;
  
      &lt;/beans&gt;
  </code></pre>
  
  <p>com/mkyong/model/Report.java</p>
  
  <pre><code>package com.mkyong.model;
  
  public class Report {
  
      private Date orderDate;
      private String impressions;
      private int clicks;
      private String earning;
  
      //getter and setter methods
  
  
  }
  </code></pre>
  
  <p>com/mkyong/App.java</p>
  
  <pre><code>package com.mkyong;
  
  import org.springframework.batch.core.Job;
  import org.springframework.batch.core.JobExecution;
  import org.springframework.batch.core.JobParameters;
  import org.springframework.batch.core.launch.JobLauncher;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  public class App {
    public static void main(String[] args) {
  
      String[] springConfig  = 
          {   "spring/batch/config/database.xml", 
              "spring/batch/config/context.xml",
              "spring/batch/jobs/job-report.xml" 
          };
  
      ApplicationContext context = 
          new ClassPathXmlApplicationContext(springConfig);
  
      JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
      Job job = (Job) context.getBean("reportJob");
  
      try {
  
          JobExecution execution = jobLauncher.run(job, new JobParameters());
          System.out.println("Exit Status : " + execution.getStatus());
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      System.out.println("Done");
  
    }
  }
  </code></pre>
  
  <p>ReportFieldSetMapper.java</p>
  
  <pre><code>package com.mkyong;
  
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import org.springframework.batch.item.file.mapping.FieldSetMapper;
  import org.springframework.batch.item.file.transform.FieldSet;
  import org.springframework.validation.BindException;
  
  import com.mkyong.model.Report;
  
  public class ReportFieldSetMapper implements FieldSetMapper&lt;Report&gt; {
  
      @Override
      public Report mapFieldSet(FieldSet fieldSet) throws BindException {
  
          Report report = new Report();
  
          report.setOrderDate(fieldSet.readDate(0,"dd/MM/yyyy"));
          report.setImpressions(fieldSet.readString (1));
          report.setClicks;(fieldSet.readInt(2));
          report.setEarning(fieldSet.readString(3));
  
      }
  
  }
  </code></pre>