Not able to track sql error in spring batch

时间:2017-05-16 09:34:49

标签: spring-batch

I am reading query from property file in my spring batch program. Whenever I make any mistake in sql, I don't get any SQL exception but my job fails and the program terminates. Any idea about how to get SQL exception in such case. For example - I deliberately gave a wrong table name in my query, instead of getting any sql error i got below exception in log.

2017-05-16 14:53:47,652 ERROR App                       main  - Exception thrown : 
org.springframework.batch.core.UnexpectedJobExecutionException: Step failure: the delegate Job failed in JobStep.
    at org.springframework.batch.core.step.job.JobStep.doExecute(JobStep.java:120)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198)
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
    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:67)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:162)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:141)
    at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
    at com.cat.pdc.batch.job.App.main(App.java:40)
2017-05-16 14:53:47,654 INFO  App                       main  - main finally ExitStatus: FAILED 

1 个答案:

答案 0 :(得分:0)

你应该添加一个监听器,并拦截异常以进行记录或任何你需要的东西。