Solved

Duplicate Spring Batch

Posted on 2013-11-26
9
3,159 Views
Last Modified: 2013-12-01
Hi,

I was trying to rerun a sample example spring batch job which convert csv file to database table, but when i try to re run, the issue is it shows  a duplicate errors
how i can set so that i will not get the duplicate error message...........

Here are sample code report called job-report.xml which is called by
====================================================================
<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">

    <bean id="report" class="com.mkyong.model.Report" scope="prototype" />
    
	<batch:job id="reportJob">
		<batch:step id="step1">
			<batch:tasklet>
<batch:chunk reader="cvsFileItemReader" writer="mysqlItemWriter"
commit-interval="2">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">

<!-- Read a csv file -->
<property name="resource" value="classpath:cvs/report.csv" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<!-- split it -->
<property name="lineTokenizer">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="names" value="date,impressions,clicks,earning" />
</bean>
</property>
<property name="fieldSetMapper">
				    
    <!-- return back to reader, rather than a mapped object. -->
    <!--
<bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper" />
				    -->
				      
	<!-- map to an object -->
<bean
Class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="prototypeBeanName" value="report" />
	</bean>
</property>

</bean>
</property>

</bean>

<bean id="mysqlItemWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource" />
	<property name="sql">
<value>
    <![CDATA[        
insert into RAW_REPORT(DATE,IMPRESSIONS,CLICKS,EARNING) values (:date, :impressions, :clicks, :earning)
            ]]>
</value>
</property>
<!-- It will take care matching between object property and sql name parameter -->
      <property name="itemSqlParameterSourceProvider">
<bean
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
</bean>
</beans>

Open in new window


==============================================================
Here is the sample main program code

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");

	}
}

Open in new window



==============================================================

Here is the error log

org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [
                    
            	insert into RAW_REPORT(DATE,IMPRESSIONS,CLICKS,EARNING) values (?, ?, ?, ?)
            
			]; Duplicate entry '6/1/13' for key 'PRIMARY'; nested exception is java.sql.BatchUpdateException: Duplicate entry '6/1/13' for key 'PRIMARY'
	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:605)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
	at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:890)
	at org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(NamedParameterBatchUpdateUtils.java:40)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate(NamedParameterJdbcTemplate.java:324)
	at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:182)
	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:131)
	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:137)
	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:152)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:131)
	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:49)
	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127)
	at com.mkyong.App.main(App.java:27)
Caused by: java.sql.BatchUpdateException: Duplicate entry '6/1/13' for key 'PRIMARY'
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:905)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:890)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)
	... 30 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '6/1/13' for key 'PRIMARY'
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
	... 34 more
26 Nov, 2013 3:40:44 PM org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run
INFO: Job: [FlowJob: [name=reportJob]] completed with the following parameters: [{}] and the following status: [FAILED]
Exit Status : FAILED
Done

Open in new window

========================================================
0
Comment
Question by:roy_sanu
  • 4
  • 2
  • 2
9 Comments
 

Author Comment

by:roy_sanu
ID: 39677651
added in the main program  with  (DuplicateKeyException e) still it gives me the same above error

thanks


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 (DuplicateKeyException e) {
		System.out.println("same data Already Exist");
		} 
		
		catch (DataAccessException e) {
		  e.printStackTrace();
		}	
			
		catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("Done");

	}
}

Open in new window

0
 
LVL 14

Expert Comment

by:jb1dev
ID: 39679561
Presumably your report.csv file contains multiple duplicate dates 6/1/13
but the table definition of RAW_REPORT column DATE is declared to be a unique primary key?
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39679856
added in the main program  with  (DuplicateKeyException e) still it gives me the same above error
The reason why adding the code that you did still gives you the same error, is because it isn't YOUR code that is printing that error message. It can't be your code that prints it because the only way that could be is if the exception was being thrown by line 14 (in your App.java snippet above), and if the exception was being thrown at line 14 then the output statement on line 15 wouldn't be executed, but it clearly is because on line 65 of you error log output above, you can see that output.

So, the error must be being printed by some code within Spring Batch (or Spring JDBC). I went looking through much of the Spring code but it is hard to find.



Can you help me by posting the lines from error log immediately before what you have posted above? That may give a clue as to what is happening.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 14

Expert Comment

by:jb1dev
ID: 39679937
I'm making a lot of assumptions here since I don't know the table definitions but,
I'm guessing the DATE column in the RAW_REPORT table is defined as a unique primary key.
Which doesn't really make sense if you expect more than one row per day.

I'm wondering if OP wanted to use TIMESTAMP as the column data type (which would include date and also time of day) rather than just DATE, which in most db implementations, and in the java sql jdbc data type, does not include hours, minutes, seconds, etc.
0
 

Author Comment

by:roy_sanu
ID: 39679977
jd1dev, your question on primary key on date is already exits, this is my data structure

CREATE TABLE raw_report (
   DATE1 VARCHAR(40) NOT NULL,
   IMPRESSIONS VARCHAR(100) NOT NULL,
   CLICKS VARCHAR(40) NOT NULL,
   EARNING varchar(40) Not NULL,
   PRIMARY KEY ( DATE1)
);

Mccarl,
Here is Ref  where i am using it

http://www.mkyong.com/spring-batch/spring-batch-example-csv-file-to-database/ 

=====================================================================
Here is the error log below, when i try to re run again it gives me the error below. I need to set a  condition that if duplicate record exists it should be  a user friendly message "Record already exists, am not able to capture that.........

=========================================================================
SEVERE: Encountered an error executing the step
org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [
                    
            	insert into RAW_REPORT(DATE1,IMPRESSIONS,CLICKS,EARNING) values (?, ?, ?, ?)
            
			]; Duplicate entry '6/1/13' for key 'PRIMARY'; nested exception is java.sql.BatchUpdateException: Duplicate entry '6/1/13' for key 'PRIMARY'
	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:605)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
	at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:890)
	at org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(NamedParameterBatchUpdateUtils.java:40)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate(NamedParameterJdbcTemplate.java:324)
	at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:182)
	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:131)
	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:137)
	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:152)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:131)
	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:49)
	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127)
	at com.mkyong.App.main(App.java:31)
Caused by: java.sql.BatchUpdateException: Duplicate entry '6/1/13' for key 'PRIMARY'
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:905)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:890)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)
	... 30 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '6/1/13' for key 'PRIMARY'
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	at com.mysql.jdbc.Util.getInstance(Util.java:386)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
	... 34 more
27 Nov, 2013 12:31:36 PM org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run
INFO: Job: [FlowJob: [name=reportJob]] completed with the following parameters: [{}] and the following status: [FAILED]
Exit Status : FAILED
Done

Open in new window

0
 

Author Comment

by:roy_sanu
ID: 39680137
I modified the  table with
   
CREATE TABLE raw_report (
   DATE1 TIMESTAMP NOT NULL,
   IMPRESSIONS VARCHAR(100) NOT NULL,
   CLICKS VARCHAR(40) NOT NULL,
   EARNING varchar(40) Not NULL,
   PRIMARY KEY (DATE1))

but it is giving me error as
==================================================================
SEVERE: Encountered an error executing the step
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [
                    
            	insert into RAW_REPORT(DATE1,IMPRESSIONS,CLICKS,EARNING) values (?, ?, ?, ?)
            
			]; Data truncation: Incorrect datetime value: '6/1/13' for column 'DATE1' at row 1; nested exception is java.sql.BatchUpdateException: Data truncation: Incorrect datetime value: '6/1/13' for column 'DATE1' at row 1
	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:605)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
	at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:890)
	at org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(NamedParameterBatchUpdateUtils.java:40)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate(NamedParameterJdbcTemplate.java:324)
	at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:182)
	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:131)
	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:137)
	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:152)
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:131)
	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:49)
	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127)
	at com.mkyong.App.main(App.java:31)
Caused by: java.sql.BatchUpdateException: Data truncation: Incorrect datetime value: '6/1/13' for column 'DATE1' at row 1
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:905)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:890)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)
	... 30 more
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '6/1/13' for column 'DATE1' at row 1
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4185)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)
	... 34 more
27 Nov, 2013 3:06:48 PM org.springframework.batch.core.launch.support.SimpleJobLauncher$1 run
INFO: Job: [FlowJob: [name=reportJob]] completed with the following parameters: [{}] and the following status: [FAILED]
Exit Status : FAILED
Done

Open in new window

Thanks
0
 

Author Comment

by:roy_sanu
ID: 39680543
I need to convert the  database date datatype changed timestamp to  date fields of string  timestamp in report.java Let me know...

public class Report {

	//SimpleDateFormat formatter = new SimpleDateFormat("MM-dd-yyyy"); 
	
	private String date;
	
	
	public String getDate() {
	
	return date;
	}

	public void setDate(String date) {
		this.date = date;
	}
	
	private String Impressions;
	private String Clicks;
	private String Earning;
	
	
	public String getImpressions() {
		return Impressions;
	}
	public void setImpressions(String impressions) {
		Impressions = impressions;
	}
	public String getClicks() {
		return Clicks;
	}
	public void setClicks(String clicks) {
		Clicks = clicks;
	}
	public String getEarning() {
		return Earning;
	}
	public void setEarning(String earning) {
		Earning = earning;
	}

	
}

Open in new window

0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39680571
You should stick to one problem at a time. You will just confuse yourself by jumping between issues. You should change you database back to the way it was, and then change the definition of your <batch:job> to the following...
	<batch:job id="reportJob">
		<batch:step id="step1">
			<batch:tasklet>
<batch:chunk reader="cvsFileItemReader" writer="mysqlItemWriter"
commit-interval="2">
         <skippable-exception-classes>
            <include class="org.springframework.dao.DuplicateKeyException"/>
         </skippable-exception-classes>
         <no-rollback-exception-classes>
            <include class="org.springframework.dao.DuplicateKeyException"/>
         </no-rollback-exception-classes>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>

Open in new window

The "skippable-exception-classes" will stop the job from failing when encountering duplicate values, and therefore it will stop the stack trace from being logged. The "no-rollback-exception-classes" is probably what you want to so that other items that are written in the same chunk still get committed.

Now, as mentioned, this will get rid of the stack trace in your logs, but at the moment it won't log anything (other than I think you can get the number of skipped items and you could log that if you want). If you do want to log something for every skipped item, then you can register an instance of SkipListener that implements the onSkipInWrite() method that logs when each item is skipped.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
Why method in Java which is called from Runnable run() doesn't need to be 'static'? 1 24
print map entry 34 69
map related example 6 48
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question