2016-04-28 15 views
1

私はorg.springframework.batch.item.database.JdbcBatchItemWriterを使用してファイルをDBに書き込み、org.springframework.batch.item.file.mapping.PassThroughFieldSetMapperを使用して列をマップしています。データがDBに挿入されず、ログにエラーが発生しませんでした。春のバッチを使用してMySQL DBにデータを読み込むことができません

<bean id="ItemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="sql"> 
     <value> 
      <![CDATA[ 
       insert into Student_Details(Name,Id,ClassId,Rank) values (:Name, :Id, :ClassId, :Rank) 
      ]]> 
     </value> 
    </property>  
    <property name="itemSqlParameterSourceProvider"> 
     <bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" /> 
    </property> 

2016-04-28 05:45:59,904 INFO [com.sam.test.mine.scheduler.SchedulerService] [fileFirmsChannelPool-2] INFO - <Ok file received: Student_details_20160116.OK> 
Apr 28, 2016 5:45:59 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run 
INFO: Job: [FlowJob: [name=StudentDetailsJob]] launched with the following parameters: [{groupId=0, size=0,filename=file:/app/data/Student_details_20160116.txt, filenames=file:/app/data/Student_details_20160116.txt, now=1461836759909,type=STUDENT_DET}] 
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.job.SimpleStepHandler handleStep 
INFO: Executing step: [cleanStudentDetails] 
2016-04-28 05:46:00,362 INFO [com.sam.test.mine.batch.JdbcUpdateTasklet] [fileFirmsChannelPool-2] INFO - <Deleted table Student_Details successfully.> 
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.job.SimpleStepHandler handleStep 
INFO: Executing step: [studentDetailsStep] 
Apr 28, 2016 5:46:00 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml] 
Apr 28, 2016 5:46:00 AM org.springframework.jdbc.support.SQLErrorCodesFactory <init> 
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana] 
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.job.SimpleStepHandler handleStep 
INFO: Executing step: [archiveStudentDetails] 
2016-04-28 05:46:00,894 INFO [com.sam.test.mine.batch.FileArchiverTasklet] [fileFirmsChannelPool-2] INFO - <Archiving ... > 
2016-04-28 05:46:00,902 INFO [com.sam.test.mine.batch.FileArchiverTasklet] [fileFirmsChannelPool-2] INFO - <success moving file to archive: /app/data/Student_details_20160116.txt to /app/archive/20160428/Student_details_20160116.txt.execution#33912> 
Apr 28, 2016 5:46:00 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run 
INFO: Job: [FlowJob: [name=StudentDetailsJob]] completed with the following parameters: [{groupId=0, size=0, filename=file:/app/data/Student_details_20160116.txt, filenames=file:/app/data/Student_details_20160116.txt, now=1461836759909, type=STUDENT_DET}] and the following status: [COMPLETED] 
2016-04-28 05:46:00,975 INFO [com.sam.test.mine.scheduler.SchedulerService] [fileFirmsChannelPool-2] INFO - <finish deleting Ok file /app/data/Student_details_20160116.OK>> 
+0

あなたの設定を(XMLサンプルから)テストしましたが、実際にデータベースにレコードが挿入されました。どのようなDMBSを使用していますか? 'dataSource'ビーンを(ユーザ/パスワードなしで)投稿できますか?依存関係に正しいドライバがありますか? – Thrax

+0

My SQLデータベースと同じライターで "org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper"を使ってデータを挿入できるので、データソースや接続の問題がないことを願っています。 "com.microsoft.sqlserver.jdbc.SQLServerDriver"はドライバです。 – Amuthan

+1

MySQL DBMSで動作させるために、私は 'com.mysql.jdbc.Driver'を使用しました。依存関係は' mysql mysql-connector-java 'です。 – Thrax

答えて

0

Iは0と読み、カウントなど、あまりにも同じWRITE_SKIP_COUNTとしてBATCH_STEP_EXECUTIONテーブルが、WRITE_COUNTにREAD_COUNT値を見ています。

-Amuthan

あなたREAD_COUNTがあなたのWRITE_SKIP_COUNTと一致すると、それは例外がskippable-exception-classes財産でスキップ可能例外として登録されているあなたのJdbcBatchItemWriterでスローされている意味しています。

<step id="step1"> 
    <tasklet> 
     <chunk reader="soemReader" writer="jdbcWriter" 
      commit-interval="10" skip-limit="10"> 
     <skippable-exception-classes> 
      <include class="com.package.YourException"/> 
     </skippable-exception-classes> 
     </chunk> 
    </tasklet> 
</step> 

このようなエラーを呑み込むようなビジネスをしていない限り、スキップ可能な例外はすべて削除します。

関連する問題