title: org.springframework.dao.DataIntegrityViolationException Caused by: java.sql.BatchUpdateException: Data truncation
body: <p>I have a running java batch process with the following:</p>
  
  <p>ApplicationContext:</p>
  
  <pre><code>&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" &gt; 
          &lt;property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/&gt;
          &lt;property name="url" value="${example.connection.url}"/&gt;
          &lt;property name="username" value="${example.connection.username}"/&gt;
          &lt;property name="password" value="${example.connection.password}"/&gt;
          &lt;property name="maxActive" value="100"/&gt;
          &lt;property name="maxWait" value="1000"/&gt;         
      &lt;/bean&gt;
  </code></pre>
  
  <p>DAOImpl:</p>
  
  <pre><code>public void batchInsertUsers(final List&lt;UserInfo&gt; userDataList) {
          logger.info("userList size::"+userDataList.size());
  
          try{
              jdbcTemplate.batchUpdate(insertUserQuery,
                      new BatchPreparedStatementSetter() {
                          public void setValues(PreparedStatement ps, int i) throws SQLException {
                              java.util.Date date= new java.util.Date();
                              UserInfo userData = userDataList.get(i);
  
                              ps.setString(1, userData.getUid());
                              ps.setString(2, userData.getFirstName());
                              ps.setString(3, userData.getMiddleName());
                              ps.setString(4, userData.getLastName());
                              ps.setTimestamp(5, null);
                              ps.setString(6, "");
                              ps.setTimestamp(7, null);
                              ps.setBoolean(8, false);
                              ps.setString(9, null);
                              ps.setString(10, userData.getUserID());
                              ps.setTimestamp(11,new Timestamp(date.getTime()));
                              userData = null;
                          }
  
                          public int getBatchSize() {
                              return userDataList.size();
                          }
                      } );
          }catch(Exception e){
              logger.error("Exception occured while inserting in Users_Temp table::",e);
              logger.error(e);
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>insertUserQuery=INSERT INTO USERS_temp(uid, FirstName, MI, LastName, SyncDate, Status, DisabledDateTime, Exclude, Notes, UpdateID, UpdateDateTime) VALUES (?,?,?,?,?,?,?,?,?,?,?)</p>
  
  <p>It runs fine everytime but once in a while it stops with below exception and I am clueless because it doesn't say anything about any data size exceeding allowed column size or violation of any constraint. Below is the exception trace:</p>
  
  <pre><code>    org.springframework.dao.DataIntegrityViolationException:   PreparedStatementCallback; SQL [INSERT INTO USERS_temp(uid, FirstName, MI, LastName, SyncDate, Status, DisabledDateTime, Exclude, Notes, UpdateID, UpdateDateTime) VALUES (?,?,?,?,?,?,?,?,?,?,?)]; Data truncation; nested exception is java.sql.BatchUpdateException: Data truncation
          at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
          at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
          at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
          at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
          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 com.example.UserDAOImpl.batchInsertUsers(UsersDAOImpl.java:175)
          at com.example.UserServiceImpl.processData(UserServiceImpl.java:184)
          at com.example.UserMain.main(UserMain.java:23)
  Caused by: java.sql.BatchUpdateException: Data truncation
          at net.sourceforge.jtds.jdbc.JtdsStatement.executeBatch(JtdsStatement.java:947)
          at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
          at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:899)
          at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1)
          at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587)
          ... 5 more
  </code></pre>
  
  <p>Its a batch process, so there are thousands of records going into DB. Has anyone come across similar situation? If yes, please shed some light.</p>
  
  <pre><code>Table structure
  
  column name       data type      allow nulls   
  UID               char(9)        N
  FirstName         varchar(50)    N
  MI                varchar(1)     Y
  LastName          varchar(50)    N
  SyncDate          datetime       Y
  Status            char(1)        N
  DisabledDateTime  datetime       Y
  Exclude           bit            N
  Notes             varchar(250)   Y
  UpdateID          varchar(10)    N
  UpdateDateTime    datetime       N
  </code></pre>
  
  <p>UID is primary key and is indexed.</p>